Unpacking multiple dictionaries in a function?

Peter Otten __peter__ at web.de
Sat Feb 12 21:51:45 CET 2011

Paul Rubin wrote:

> Martin De Kauwe <mdekauwe at gmail.com> writes:
>>     def wrapper(*old_dicts):
>>         dict={}
>>         for d in old_dicts:
>>             dict.update(d)
>>         return f(**dict)
> Untested:
>     from itertools import chain
>     def wrapper(*old_dicts):
>        return f(**dict(chain(d.iteritems() for d in old_dicts)))

I think you need chain.from_iterable() instead of chain().

More information about the Python-list mailing list