I'm trying to create a function in python that takes any number of arguments, runs some operations on the arguments and lastly returns the new values. Eg:
def foo(*args):
return *[i ** 2 for i in args] # error: cant use starred expression here
a, b, c, d = foo(2, 15, 17, 21)
instead of "unpacking" the list it just spits out a syntax error. I could technically leave out the "unpacking" all together and just have the user write
def foo(*args):
return [i ** 2 for i in args]
a, b, c, d = foo(2, 15, 17, 21) # works
e = foo(82) # e is now a list and not just the value
this works when having multiple arguments but not when I only give one. Is there any way to do this easily without the need of using an if-statement to check the number of inputs given?