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

Keep correct key order and values when flatdict has nested list #33

Closed wsantos closed 5 years ago

wsantos commented 5 years ago

How to reproduce:

import flatdict
from pprint import pprint

dd = {
    "inputs": [
        {"name": 0},
        {"name": 1},
        {"name": 2},
        {"name": 3},
        {"name": 4},
        {"name": 5},
        {"name": 6},
        {"name": 7},
        {"name": 8},
        {"name": 9},
        {"name": 10},
    ],
}

fd = flatdict.FlatterDict(dd)
pprint(fd.keys())
pprint(fd.as_dict())

Output from 3.3.0

['inputs:0:name',
 'inputs:10:name',
 'inputs:1:name',
 'inputs:2:name',
 'inputs:3:name',
 'inputs:4:name',
 'inputs:5:name',
 'inputs:6:name',
 'inputs:7:name',
 'inputs:8:name',
 'inputs:9:name']
{'inputs': [{'name': 0},
            {'name': 1},
            {'name': 10},
            {'name': 2},
            {'name': 3},
            {'name': 4},
            {'name': 5},
            {'name': 6},
            {'name': 7},
            {'name': 8},
            {'name': 9}]}

Expected output

['inputs:0:name',
 'inputs:1:name',
 'inputs:2:name',
 'inputs:3:name',
 'inputs:4:name',
 'inputs:5:name',
 'inputs:6:name',
 'inputs:7:name',
 'inputs:8:name',
 'inputs:9:name',
 'inputs:10:name']
{'inputs': [{'name': 0},
            {'name': 1},
            {'name': 2},
            {'name': 3},
            {'name': 4},
            {'name': 5},
            {'name': 6},
            {'name': 7},
            {'name': 8},
            {'name': 9},
            {'name': 10}]}
gmr commented 5 years ago

Not sure if I'd consider this a point release instead of a minor, given the behavioral change.

Thanks for the PR. I'll adjust the versioning.