0

I have a function f(a,b,c) waiting for 3 int. I have a list t = list(1,2,3) that i want to input to f : f(t). But it doesn't work. What is the easiest way to do it.

EDIT : t = list('1','2','3')

Thank you

The Answer
  • 269
  • 1
  • 3
  • 11

3 Answers3

5

You need to unpack the values present in list t.

 f(*t)

Example:

>>> def f(a,b,c):
        print(a,b,c)

>>> t = [1,2,3]
>>> f(*t)
1 2 3

OR

>>> def f(a,b,c):
        print(a,b,c)


>>> t = ['1','2','3']
>>> f(*map(int,t))
1 2 3
Avinash Raj
  • 166,785
  • 24
  • 204
  • 249
0

You will have to pass the values as follows:

f(t[0], t[1], t[2])
Mo H.
  • 1,766
  • 1
  • 20
  • 28
0

You can call the function like this:

f(t[0],t[1],t[2])

Cheers!

Wealot
  • 201
  • 2
  • 9