*This is a fork of Gavin M. Roy 's Flat Dict package : https://github.com/gmr/flatdict
I have modified it to use tuples to represent the key tree instead of delimited strings. This extends it to allow arbitrary types (except tuples) to be used as keys.
(NOTE the FlatterDict
class has been removed.)
``TupleFlatDict``is a dict class that allows for single level key/value pair mapping of nested dictionaries.
You can interact with TupleFlatDict
like a normal dictionary and access child
dictionaries as you normally would or with the composite key.
For example:
value = TupleFlatDict({'foo': {'bar': 'baz', 'qux': 'corge'}, 1:{2:'two',3:'three'}})
would be the same as:
value == {('foo', 'bar'): 'baz', ('foo', 'qux'): 'corge', (1, 2): 'two', (1, 3): 'three'}
values can be accessed as:
print(foo['foo','bar'])
# or
print(foo['foo']['bar'])