gmr / flatdict

Python module for interacting with nested dicts as a single level dict with delimited keys.
https://flatdict.readthedocs.io
BSD 3-Clause "New" or "Revised" License
112 stars 32 forks source link

Code example in the documentation does not work as expected #34

Closed antimirov closed 5 years ago

antimirov commented 5 years ago

The example from the documentation on https://flatdict.readthedocs.io/en/stable/ does not work for me.

Setup:

(testenv) $ python
Python 3.7.4 (default, Jul 11 2019, 01:08:00)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import flatdict

This one works:

For example:

foo = {'foo': {'bar': 'baz', 'qux': 'corge'}} is represented as:

{'foo:bar': 'baz', 'foo:qux': 'corge'}

>>> foo = {'foo': {'bar': 'baz', 'qux': 'corge'}}
>>> flatdict.FlatDict(foo)
<FlatDict id=4354298064 {'foo:bar': 'baz', 'foo:qux': 'corge'}>"

But his one does not work:

Additionally, lists and tuples are also converted into dicts using enumerate().

For example:

d = {'list': ['a', 'b', 'c',]} Will be flattened as follows:

flat = {'list:0': 'a', 'list:1': 'b', 'list:2': 'c'}


>>> d = {'list': ['a', 'b', 'c',]}
>>> flatdict.FlatDict(d)
<FlatDict id=4354748368 {'list': ['a', 'b', 'c']}>"```

Am I correct to assume that flattening does not work for the lists on the first level? Or does the example assume using of FlatterDict here?
gmr commented 5 years ago

Thanks, will update, that's in the FlatterDict class.