Unpacking sequences and keywords in one function call

ram rickmorrison at gmail.com
Tue Nov 14 02:06:18 CET 2006

Stupid question #983098403:

I can't seem to pass an unpacked sequence and keyword arguments to a
function at the same time. What am I doing wrong?

def f(*args, **kw):
    for a in args:
        print 'arg:', a
    for (k,v) in kw.iteritems():
        print k, '=', v

>>> f(1,2)
arg: 1
arg: 2

>>> f(*[1,2])
arg: 1
arg: 2

>>> f(1,2, a=1)
arg: 1
arg: 2
a = 1

>>> f(*[1,2], a=1)
    File "<stdin>", line 1
      f(*[1,2], a=1)
    SyntaxError: invalid syntax 


More information about the Python-list mailing list