Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make use of collections.ChainMap to simplify the code #11522

Closed
wants to merge 2 commits into from
Closed

make use of collections.ChainMap to simplify the code #11522

wants to merge 2 commits into from

Conversation

linchiwei123
Copy link

No description provided.

@felixxm
Copy link
Member

felixxm commented Jun 28, 2019

Thanks for this patch, however ChainMap is more complicated structure that is not a "normal" dict:

>>> a = {'b': 1, 'c': 18, 'd': 90}
>>> b = {'c': 77}
>>> c = {'c': 88, 'd': 91, 'e': 115, 'f': 300}
>>> isinstance(ChainMap(a, b, c))
False
>>> ChainMap(a, b, c)
ChainMap({'b': 1, 'c': 18, 'd': 90}, {'c': 77}, {'c': 88, 'd': 91, 'e': 115, 'f': 300})

Moreover it has different order of keys, e.g.

>>> list(ChainMap(a, b, c).keys())
['b', 'c', 'd', 'e', 'f']
>>> list(merge_dicts([a, b, c]).keys())
['c', 'd', 'e', 'f', 'b']

@felixxm felixxm closed this Jun 28, 2019
@linchiwei123
Copy link
Author

Thanks for this patch, however ChainMap is more complicated structure that is not a "normal" dict:

>>> a = {'b': 1, 'c': 18, 'd': 90}
>>> b = {'c': 77}
>>> c = {'c': 88, 'd': 91, 'e': 115, 'f': 300}
>>> isinstance(ChainMap(a, b, c))
False
>>> ChainMap(a, b, c)
ChainMap({'b': 1, 'c': 18, 'd': 90}, {'c': 77}, {'c': 88, 'd': 91, 'e': 115, 'f': 300})

Moreover it has different order of keys, e.g.

>>> list(ChainMap(a, b, c).keys())
['b', 'c', 'd', 'e', 'f']
>>> list(merge_dicts([a, b, c]).keys())
['c', 'd', 'e', 'f', 'b']

Thanks for the information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants