I have two possible ways to call a function.
With a list:
some_list = [1,2,3,4]
my_function(some_list)
And with an unpacked list or a few arguments:
my_function(*some_list) == my_function(1,2,3,4)
which is equal to the first case:
my_function(some_list) == my_function(*some_list) == my_function(1,2,3,4)
In a function, my_function
I want to iterate over a list. Thus, for the frist case, the function looks like this:
def my_function(arg):
for i in arg:
Now for the second case, I repackaged the unpacked list, as a result we get the following function:
def my_function(*arg):
for i in arg:
Is there a way to have a good single function for both cases?
source
share