A dictionary list?

Francis Avila francisgavila at yahoo.com
Tue Dec 23 23:41:50 EST 2003


Steve wrote in message <3fe91593 at clarion.carno.net.au>...
>Hi,
>
>How can I create a list of a dictionary? (in other words, I need to
>create an array of a dictionary). Please help!
>
>Steve

I am unsure how to interpret "of a".  Do you mean a list *from* a
dictionary" or a list *of* dictionaries? "Array of a dictionary" suggests
you mean "array of dictionaries".

dictarray = [{} for i in range(10)]

listfromdict = {}.items()

Note the subtle trap of using 'dictarray = [{}]*10' instead: this will
create only one dictionary, with ten references to it.


In any case, this is an *extremely* basic question.  Have you gone through
the included tutorial yet?
--
Francis Avila





More information about the Python-list mailing list