I am trying to write a function to take in any number of different lists or tuples as arguments and return one big list.
def addify(*args):
big_list = list()
for iterable in args:
if isinstance(iterable, tuple):
big_list.extend(list(iterable))
else:
big_list.extend(iterable)
return big_list
>>> print addify((1,2,3), [2, 5, 3], (3,1,3), [3, 2344, 3])
[1, 2, 3, 2, 5, 3, 3, 1, 3, 3, 2344, 3]
I was learning about args and kwargs, and my code is working all right, but this seems like too much code for something so simple.
There must be a better way than writing a long function to check if an argument is a tuple and if it is add convert it to a list and then add it on. That just seems bloated.