Passing ints to a function

stayvoid stayvoid at gmail.com
Fri Jun 8 19:41:40 EDT 2012


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?

This wouldn't work because we're passing a list not ints:
function(a)
function(b)
function(c)

This wouldn't work too (the reason is the same):
def foo(x):
  return x[0], x[1], x[2], x[3], x[4], x[5]

function(foo(a))
function(foo(b))
function(foo(c))

This would work, but it's not pythonic at all (imagine that you want
to call it 10 times or even more).

function(a[0], a[1], a[2], a[3], a[4], a[5])
function(b[0], b[1], b[2], b[3], b[4], b[5])
function(c[0], c[1], c[2], c[3], c[4], c[5])

Thanks










More information about the Python-list mailing list