How to expand a list to function arguments in Python -
this question has answer here:
- *args , **kwargs? [duplicate] 11 answers
is there syntax allows expand list arguments of function call?
example:
# trivial example function, not meant useful. def foo(x,y,z): return "%d, %d, %d" %(x,y,z) # list of values want pass foo. values = [1,2,3] # want this, , result "1, 2, 3": foo( values.howdoyouexpandme() )
it exists, it's hard search for. think people call "splat" operator.
it's in documentation "unpacking argument lists".
you'd use this: foo(*values)
. there's 1 dictionaries:
d = {'a': 1, 'b': 2} def foo(a, b): pass foo(**d)
Comments
Post a Comment