Re:Toolz: A functional standard library for Python
by calebm on Tuesday May 12, 2015 @10:47AM
(#9532117)
Does it have a recursive dictionary merge - something like merge({'a': {'b': 1}}, {'a': {'c': 2}}) -> {'a': {'b': 1, 'c': 2}} ?
[ Parent
| on HN ]
Re:Toolz: A functional standard library for Python
by alien_robot on Tuesday May 12, 2015 @03:35PM
(#9534291)
Wish 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
Re:Toolz: A functional standard library for Python
by mrocklin on Tuesday May 12, 2015 @03:05PM
(#9534091)
You 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