I'm trying to create a function that will do something like this:
list1 = ['a', 'b', 'c']
list2 = ['1', '2', '3']
option = input('your option: ')
printElements(option)
So if the user writes 'list1', the function should print a b c
I'm trying to create a function that will do something like this:
list1 = ['a', 'b', 'c']
list2 = ['1', '2', '3']
option = input('your option: ')
printElements(option)
So if the user writes 'list1', the function should print a b c
You can use ast.literal_eval
to evaluate your variable and get the list you want.
printElements(ast.literal_eval(option))
A better way to do it would be to store your lists in a dictionary and then use option
as a key:
d = {"list1": list1, "list2": list2}
printElements(d[option])
I think this is what you want:
list = input("Your option : ")
def printWords(list):
for value in list:
print(value)