(newbie) Array of dictionaries

Marty Brundage brundage at aimnet.com
Sat Oct 2 15:29:39 EDT 1999


Yes, and it works for me.  I didn't think it would be this simple!  (I
was looking for an explicit declaration, and got hung up on that
issue.)

Some replies have pointed out an explicit declaration syntax of

a=[{},{},...]

Which is only good for small fixed length arrays of dictionaries.  It
seems odd that the general case does not require an explicit
delaration.

Thanks to all who replied.


Marty


Janko Hauser <hauser at ifm.uni-kiel.de> wrote:

>Perhaps I do not understand right, or you have a syntax problem in
>your tests.
>
>>>> a=[]
>>>> a.append({'key1':'hello','key2':' world'})
>>>> a.append({'key1':'another ','key2':'world'})
>>>> a[0]['key1']
>'hello'
>>>> a[1]['key1']
>'another '
>>>> 
>
>So this looks equivilant to 'dict[n][<key>]', but is this what you
>want?
>
>HTH
>
>__Janko





More information about the Python-list mailing list