Skip to content

Instantly share code, notes, and snippets.

@jeroenpelgrims
Created May 24, 2010 15:44
Show Gist options
  • Save jeroenpelgrims/412022 to your computer and use it in GitHub Desktop.
Save jeroenpelgrims/412022 to your computer and use it in GitHub Desktop.
mkdict usage
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