How to expand a list to function arguments in Python -


this question has answer here:

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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -