Re: Basic list/dictionary question

2009-11-11 Thread Mick Krippendorf
Ralax wrote: > On Nov 11, 8:58 pm, Chris Rebert wrote: >> In [2]: def foo(z, a=[]): >>...: a.append(z) >>...: return a >>...: >> >> In [3]: foo(1) >> Out[3]: [1] >> >> In [4]: foo(2) >> Out[4]: [1, 2] >> >> In [5]: foo(2) >> Out[5]: [1, 2, 2] >> >> In [6]: foo(3) >> Out[6]: [1,

Re: Basic list/dictionary question

2009-11-11 Thread Ralax
On Nov 11, 8:58 pm, Chris Rebert wrote: > On Wed, Nov 11, 2009 at 4:16 AM, Daniel Jowett > wrote: > > Greetings, > > > I'm trying to categorize items in a list, by copying them into a > > dictionary... > > A simple example with strings doesn't seem to work how I'd expect: > > basket = ['app

Re: Basic list/dictionary question

2009-11-11 Thread Daniel Jowett
Thanks Chris, yes it's becoming clearer now. And defaultdict looks nice - unfortunately I'm stuck to python 2.4 as I'm using Plone. Thanks again, Daniel 2009/11/11 Chris Rebert > On Wed, Nov 11, 2009 at 4:16 AM, Daniel Jowett > wrote: > > Greetings, > > > > I'm trying to categorize items in

Re: Basic list/dictionary question

2009-11-11 Thread Chris Rebert
On Wed, Nov 11, 2009 at 4:16 AM, Daniel Jowett wrote: > Greetings, > > I'm trying to categorize items in a list, by copying them into a > dictionary... > A simple example with strings doesn't seem to work how I'd expect: > basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']

Basic list/dictionary question

2009-11-11 Thread Daniel Jowett
Greetings, I'm trying to categorize items in a list, by copying them into a dictionary... A simple example with strings doesn't seem to work how I'd expect: >>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> d = {} >>> d = d.fromkeys(basket, []) >>> d {'orange': [], 'pear':