"Angela Yang" <[EMAIL PROTECTED]> wrote

But for dictionaries, it is key - value pairs. But I need key -> multiple values.

But a value can be a list.

d = {}
d['odd'] = [1,3,5,7]
d['even'] = [2,4,6,8]

print d['odd'][2]    # = 5


See the Raw Materials top[ic in my tutorial for another
example using a dictionary to store address data:

addressBook = {
... 'Fred' : ['Fred', '9 Some St',' Anytown', '0123456789'],
... 'Rose' : ['Rose', '11 Nother St', 'SomePlace', '0987654321']
... }>>> print addressBook['Rose']
['Rose', '11 Nother St', 'SomePlace', '0987654321']
print addressBook['Fred'][3]
0123456789
HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to