Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment