Assimilation
Assimilation

Reputation: 3

Python - Passing contents of list existing as dictionary value to a function that accepts multiple arguments?

New to programming, still getting the hang of Python.I am trying to pass the contents of a list which exists as a dictionary value, to a function that accepts multiple arguments. I have tried:

dict = {'1':['option1', 'option2', 'option3']}  

def print_list(param1, param2, param3):
    print param1
    print param2
    print param3

print_list(dict['1'])  

However, I recieve the error:

TypeError: print_list() takes exactly 3 arguments (1 given)  

After some fiddling I understand why it doesn't work but short of trying to figure out a way to assign each list item to it's own variable, and then passing the variables to the function I am unsure how to solve this problem. I am working on a choose-your-own-adventure project that compares user input to the dictionary key, and passes the associated values (which are in a list) as arguments to the function producing the new scenario. Any advice?

Upvotes: 0

Views: 3555

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799150

Yes. Read the bleeping tutorial.

print_list(*dict['1'])

Upvotes: 1

Related Questions