In the following code, how do I pass the dictionary to func2. How should func2 be called?
def func2(a,**c):
if len(c) > 0:
print len(c)
print c
u={'a':1,'b':2}
func2(1,u)
Just as it accepts them:
func2(1,**u)
def func2(a,c): ... and func2(1,u) would also work. using variable arguments or standard arguments depends on what you are trying to achieve.This won't run, because there are multiple parameters for the name a.
But if you change it to:
def func2(x,**c):
if len(c) > 0:
print len(c)
print c
Then you call it as:
func2(1, a=1, b=2)
or
u={'a':1,'b':2}
func2(1, **u)
forloop still won't work. Get rid of theand 'a' in cand it would, not sure what that clause is trying to do?