Tuesday, 15 April 2014

python - pass multiple dictionaries to a function as an argument -



python - pass multiple dictionaries to a function as an argument -

i have 2 dictionaries: sp=dict{'key1':'value1','key2':'value2'}, cp=dict{'key1':'value1','key2':'value2'}

i have function take 2 dictionaries inputs, don't know how that.

i'd tried:

def test(**sp,**cp): print sp.keys(),cp.keys() test(**sp,**cp)

the real function more complicated lots of modification of 2 dictionaries. simple test function doesn't work me :(

if want take 2 dictionaries separate arguments, do

def test(sp, cp): print sp.keys(),cp.keys() test(sp, cp)

you utilize ** when want pass individual key/value pairs of dictionary separate keyword arguments. if you're passing whole dictionary single argument, pass it, same way other argument value.

python dictionary arguments

No comments:

Post a Comment