Passing ints to a function

Jussi Piitulainen jpiitula at ling.helsinki.fi
Sat Jun 9 04:29:13 EDT 2012


stayvoid writes:

> > You want to unpack the list:
> >
> > function(*a)  # like function(a[0], a[1], a[2], ...)
> 
> Awesome! I forgot about this.

Here's something you could have thought of for yourself even when you
didn't remember that Python does have special built-in support for
applying a function to a list of arguments:

def five(func, args):
   a, b, c, d, e = args
   return func(a, b, c, d, e)

five(function, a)
five(function, b)
five(function, c)

for args in argses:
   five(function, args)

The point is that the function itself can be passed as an argument to
the auxiliary function that extracts the individual arguments from the
list.



More information about the Python-list mailing list