I have two functions, fun1 and fun2, which take as inputs a string and a number, respectively. They also both get the same variable, a, as input. This is the code:
a = ['A','X','R','N','L']
def fun1(string,vect):
out = []
for letter in vect:
out. append(string+letter)
return out
def fun2(number,vect):
out = []
for letter in vect:
out.append(str(number)+letter)
return out
x = fun1('Hello ',a)
y = fun2(2,a)
The functions perform some nonsense operations. My goal would be to rewrite the code in such a way that the variable a is shared between the functions, so that they do not take it as input anymore.
One way to remove variable a as input would be by defining it within the functions themselves, but unfortunately that is not very elegant.
What is a possible way to reach my goal?
The functions should operate in the same way, but the input arguments should only be the string and the number (fun1(string), fun2(number)).
a. Try justfor letter in a: