Passing ints to a function
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Jun 8 19:56:47 EDT 2012
On Fri, 08 Jun 2012 16:41:40 -0700, stayvoid wrote:
> Hello,
>
> I want to pass several values to a function which is located on a server
> (so I can't change its behavior). That function only accepts five values
> which must be ints.
>
> There are several lists:
> a = [1, 2, 3, 4, 5]
> b = [5, 4, 3, 2, 1]
> c = [0, 0, 0, 0, 0]
>
> I want to pass each value from these lists to that function. What is the
> most pythonic way?
You want to unpack the list:
function(*a) # like function(a[0], a[1], a[2], ...)
If you have many lists, use a for-loop:
for L in (a, b, c):
function(*L)
--
Steven
More information about the Python-list
mailing list