string formatting with mapping & '*'... is this a bug?

Alex Martelli aleaxit at yahoo.com
Thu Sep 9 18:20:24 EDT 2004


Diez B. Roggisch <deetsNOSPAM at web.de> wrote:
   ...
> map2 = dict(map.items() + [(str(i), v) for i, v in enumerate(vals)])

An equivalent ctor call that's slightly better, IMHO:

map2 = dict([ (str(i),v) for i,v in enumerate(vals) ], **map)

Don't ignore the power of dict's keyword arguments...

> Not perfect, but IMHO better than your eval-based solution.

I agree, mine is just a tiny improvement on your post, IMHO.


Alex



More information about the Python-list mailing list