Newbie help with array handling

7stud bbxx789_05ss at
Thu Apr 12 11:02:41 CEST 2007

loial wrote:
> I am new to python and am converting an awk script to python
> I need to store some data in an array/table of some form
> keyvalue1, value1, value2, value3
> keyvalue2, value1,value2, value3
> keyvalue3, value1,value2,value3
> etc
> I will later need to sort in keyvalue order and also need to be able
> to check if a key already exists
> It is not clear how to do this in python. All the examples I see have
> just a key and a single value

Any python type can be a value for a key/value pair.  See if this

mydict = { "zkeyvalue1":[1, "red", 2.5], "akeyvalue2":[1.5, "black",
30] }

key = "keyvalue50"
if key in mydict:
    print "found it"
    print "invalid key"

lst = sorted(mydict)
print lst

for key in lst:
    print mydict[key],

More information about the Python-list mailing list