0

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?

1
  • 1
    Best not to shadow the builtin list with your own variable. I've used lst instead in my answer Commented Mar 24, 2015 at 4:52

2 Answers 2

3

Do you mean?

func(*lst[0])

Often you might loop over the list

for item in lst:
    func(*item)
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.