20 ms·
Does it have a recursive dictionary merge - something like merge({'a': {'b': 1}}, {'a': {'c': 2}}) -> {'a': {'b': 1, 'c': 2}} ?
by calebm 11y ago
Does it have a recursive dictionary merge - something like merge({'a': {'b': 1}}, {'a': {'c': 2}}) -> {'a': {'b': 1, 'c': 2}} ?
- mrocklin 11y agoYou can manage this by composing merge and merge_with In [1]: data = [{'a': {'b': 1}}, {'a': {'c': 2}}] In [2]: from toolz import merge, merge_with In [3]: merge_with(merge, data) Out[3]: {'a': {'b': 1, 'c': 2}} You'd have to be a bit clever to go fully recursive
- alien_robot 11y agoWish I had known I could compose something from existing functional libs, but I created this simple function to solve that very problem. https://gist.github.com/angstwad/bf22d1822c38a92ec0a9 https://gist.github.com/angstwad/bf22d1822c38a92ec0a9