(newbie) Array of dictionaries

Marty Brundage brundage at aimnet.com
Sat Oct 2 16:52:49 EDT 1999


Marty Brundage <brundage at aimnet.com> wrote:


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

After posting this I tried again and found it's incorrect, so I am
posting this correction.  The following solution, which works, was
privately emailed to me:


dicts = []
for x in range( 20):
	dicts.append( {})

## assign values
dicts[0]['this'] = 'that'
dicts[18]['thos'] = 'them'
dicts[2]['this'] = 'wherefore'

## retrieve values from all dicts
for dict in dicts:
	print dict.get( 'this' )

## retrieve single values
print dict[18]['thos']





More information about the Python-list mailing list