Python Cookbook dict problem

Dave Reed dreed at capital.edu
Tue Jul 30 16:01:27 EDT 2002


I'm trying the following Python Cookbook recipe with python2.2


def makedict(**kwargs):
    return kwargs
data = makedict(red=1, green=2, blue=3)
def dodict(*args, **kwds):
    d = {}
    for k, v in args: d[k] = v
    d.update(kwds)
    return d
tada = dodict(*data.items(), yellow=2, green=4)


but I get an error with the last line:
>>> tada = dodict(*data.items(), yellow=2, green=4)
  File "<stdin>", line 1
    tada = dodict(*data.items(), yellow=2, green=4)
                                      ^
SyntaxError: invalid syntax

What's wrong?

Thanks,
Dave




More information about the Python-list mailing list