Created
May 24, 2010 15:44
-
-
Save jeroenpelgrims/412022 to your computer and use it in GitHub Desktop.
mkdict usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mkdict import mkdict | |
d = mkdict({ | |
'key1' : 'value1', #regular dictionary usage | |
('key2', 'key3') : 'value2' #these tuple keys will be unpacked to regular keys | |
}) | |
print d['key1'] #value1 | |
print d['key2'] #value2 | |
print d['key3'] #value2 | |
d['key4'] = 'value3' | |
d[('key5', 'key6')] = 'value4' | |
print d['key4'] #value3 | |
print d['key5'] #value4 | |
print d['key6'] #value4 | |
d.set(('tkey1', 'tkey2'), 'value5', tupleKey=True) | |
print d['tkey1'] #KeyError | |
print d[('tkey1', 'tkey2')] #value5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment