Reputation: 144
So i have a function which takes multiple values:
def kgV(a,b, *rest):
#the function itself doesnt matter for the question
#beside that it returns an int no matter how many arguments where passed
now i have a list or range():
# for example
myRange = range(2, 10)
myList = [2,9,15]
Now i want it to possible to give my Function the list or range as parameter so that it works as if i had given the every int of the range or list as parameter.
#how can i make this work?
kgV(myRange)
kgV(myList)
i tried some things like: for i in a etc but they all returned errors :-/
edit: i just solved it using a help function but it seems a very un pythonic way of doing it, so is there a more pythonic / generic way of doing it?
def kgVList(liste):
result = liste[0]
for i in liste:
result = kgV(i, result)
return result
Upvotes: 1
Views: 121