Skip to content

Empty list [] in FlatterDict converts to empty dictionary {} #54

Description

@ttamg

This is also related to issue #43 but in the case where our nested dictionary has empty lists []

In this case, not only do we have the empty <FlatterDict {}>, but in the flat form it encodes the empty list as an empty dictionary instead.

In the original as_dict() form it is correct as you would expect. The issue is in the flattened form.

Here is a simple example

dict_ = {"age": 25, "siblings": []}

flat = flatdict.FlatterDict(dict_)

print(flat.as_dict())

print([(k, v) for k, v in flat.items()])

print(flat['siblings'])

Outputs

{'age': 25, 'siblings': []}

[('age', 25), ('siblings', <FlatterDict id=5520522448 {}>")]

{}    # wrong should be []

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions