Some similar questions have been answered here, but they all pertain to using a list as a variable within the function. I am looking to use a list as the function definition:
varlist = ('a',
'b',
'c',
'd',
'e')
def func(*input):
output = ""
for item in input:
output += item
return output
a = "I'll "
b = "have "
c = "a "
d = "cheese "
e = "sandwich."
print func(*varlist)
This returns abcde, when I'm trying to get I'll have a cheese sandwich. In other words, the function is using the values from the list as the inputs, rather than using them as variables, which I define below. Of course, when I redefine:
def func(a,b,c,d,e):
output = a+b+c+d+e
return output
and define a through e I get the correct output.
The code above is a gross oversimplification, but here's the goal: I am hoping to be able to remove d from my list (or add f to my list), and have it tell me I'll have a sandwich. (or I'll have a cheese sandwich, please.) without having to redefine the function each time I need to handle a different number of variables. Any thoughts are much appreciated.