Unpacking multiple dictionaries in a function?

Martin De Kauwe mdekauwe at gmail.com
Sat Feb 12 12:08:04 EST 2011


Hi,

Is there a better way to unpack more than one dictionary in a function
than...

def unpack_dicts(f):
    def wrapper(*old_dicts):
        dict={}
        for d in old_dicts:
            dict.update(d)
        return f(**dict)
    return wrapper

@unpack_dicts
def some_func(a=None, b=None, c=None):
    print a, b, c

d1 = {'a': 20.0, 'b': '-1'}
d2 = {'c': 33.0}

some_func(d1, d2)

thanks



More information about the Python-list mailing list