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
111 stars 32 forks source link

update flatterdict to have deeply nested dicts and lists (#21) #28

Closed mileslucas closed 5 years ago

mileslucas commented 5 years ago

Update allowing deeply nisted dicts and other iterables in FlatterDict (#21 solved).

Simple example:

>>> a = [[1, 2], [3, 4]]
>>> d = FlatterDict({'a': a})
>>> print(d)
{
    'a:0:0': 1,
    'a:0:1': 2,
    'a:1:0': 3,
    'a:1:1': 4
}
>>> print(d.as_dict())
{
    'a': [[1, 2],
        [3, 4]]
}

Similaraly

>>> a = [{'a': 1, 'b':2}]
>>> d = FlatterDict({'a': a})
>>> print(d)
{
    'a:0:a': 1,
    'a:0:b': 2
}
>>> print(d.as_dict())
{
    'a': [{
        'a': 1,
        'b': 2
    }]
}

(Above printing may not be doctest ready but the underlying logic should still stand).

As before I've formatted everything with YAPF and made sure to keep maximal coverage (99%).

I left this under version 3.1.1 to make that patch a little more substantial.

gmr commented 5 years ago

Going to drop 3.2.0 unless you have any other PRs pending

mileslucas commented 5 years ago

I have one more pending to fix the setting and updating of the nested dicts/iterables!