Reputation: 3
Trying to use the elements of nested lists for the arguments of a function
list = [[ "stringA" , 11, 22], [ "stringB", 33 , 44]]
def func ( 'str' , a , b ):
I know how to call a single element: list[0][1] and func(*list) to use the lists as an argument.
How do I use the individual elements?
Upvotes: 0
Views: 2271
Reputation: 691
You seem to be trying to unzip the values of list. Try this.
list1 = [[ "stringA" , 11, 22], [ "stringB", 33 , 44]]
def func(string, a, b):
print string, a, b
for i in list1:
func(*i)
Output:
stringA 11 22
stringB 33 44
Upvotes: 0
Reputation: 304205
Do you mean?
func(*lst[0])
Often you might loop over the list
for item in lst:
func(*item)
Upvotes: 3