[Tutor] FW: Having list in dict type

dman dsh8290@rit.edu
Tue, 4 Dec 2001 16:02:05 -0500

On Tue, Dec 04, 2001 at 02:30:22AM -0800, Mariappan, MaharajanX wrote:
| Hi Folks!
| Is it posible for dictionary type's value part to be a list like below,
| { "key1", ["name", "value"]
|   "key2", ["name", "value"]
| If yes, 

Yes.  The keys must be hashable, but the values can be anything.

| 1) how can I gennerate this data dynamically[ Asuume that I have all
| the string values]

It is not enough to know that you have the data, but _how_ you have it
is important.  If they are already in the lists, then the question is
meaningless.  If it is in a file that you need to parse, then (also
knowing the format!) we can give suggestions.  It is also necessary to
know what determines what a key is and what the related values should
be, otherwise we're just making up random data with random rules for
creating it.

| 2) Hiw can I traverse and print all the strings from this data.

# python 2.2
for key in dict :
    print key , dict[ key ]

# all versions
for keys in dict.keys() :
    print key , dict[ key]



"GUIs normally make it simple to accomplish simple actions and
impossible to accomplish complex actions."
    --Doug Gwyn  (22/Jun/91 in comp.unix.wizards)