0

This is more of a curiosity than a necessary use case but I would like to edit the following behavior:

>>> from collections import ChainMap
>>> x={'a':3,'b':4,'c':5}
>>> y={'d':33,'e':45,'c':7}
>>> z={'aa':3,'bb':4,'cc':5}
>>> def foo(a,b,c,cc,**kwargs):
...     print(a,b,c,cc)

>>> map = ChainMap(x,y,z)
>>> map
ChainMap({'a': 3, 'b': 4, 'c': 5}, {'d': 33, 'e': 45, 'c': 7}, {'aa': 3, 'bb': 4, 'cc': 5})

>>> foo(**map)
3 4 5 5

Is it at all possible to change the behavior of ** do custom things like return the sum of repeated keys. In the above case it would print 3 4 12 5 or give the last instance not the first 3 4 7 5?

bison
  • 739
  • 5
  • 21
  • 1
    Related: [Change what the *splat and **splatty-splat operators do to my object](https://stackoverflow.com/q/22365847/674039) – wim Aug 22 '18 at 03:46
  • thanks that is what I was looking for, also I approve of this person's naming convention. editing `splatty-splat` will be useful – bison Aug 22 '18 at 04:01
  • OK, since it pretty much answers the question I will close as duplicate then. – wim Aug 22 '18 at 04:17

0 Answers0