Possible Duplicate:
iterating one key in a python multidimensional associative array
i created a dictionary on 2 dimensions myaddresses['john','smith'] = "address 1" myaddresses['john','doe'] = "address 2"
How can i iterate over one dimension in the fashion
for key in myaddresses.keys('john'):
Bad news: you can't (not directly at least). What you did was not a "2 dimensions" dict, but a dict with tuples (string pairs in your case) as keys, and only the hash value of the key is used (as usually with hashtables). What you want requires a sequential lookup, ie:
Needless to say that it kind of defeat the whole point of using a dict. Err... what about using a proper relational DB instead ?
Try:
It iterates over all keys, so it might not be the most efficient way, but I'll just state the obvious method in case you overlooked it: