The star *
syntax in a function or method signature packs positional arguments into a tuple
(see this answer for lots of details). Your second function receives a single argument, called m
, that looks (for example) like this:
([1, 2, 3], [5, 6, 7])
If you want to then access each member of that tuple (each argument) individually, you must do that explicitly--Python can't magically intuit that you want to add all your arguments together.
def joiner(*args):
o = []
for arg in args: # Iterate over each argument your function received.
o += arg # or better, o.extend(arg)
return o
There are also tools that already exist to do this for you: specifically, itertools.chain
:
import itertools
def joiner(*m):
return list(itertools.chain(*m))
Of course at that point (as others have mentioned), you might as well not write the joiner
function at all, since it's just a few extra steps under the hood to wrap an itertools.chain
call.
...Actually, any time you do pretty much anything with one or more iterables, you should go look at the itertools
module and see if someone has already implemented it for you. :-)