dict comprehension

Ryan Ginstrom software at ginstrom.com
Fri Feb 1 01:06:16 EST 2008


> On Behalf Of Daniel Fetchinson
> What does the author mean here? What's the Preferably One Way 
> (TM) to do something analogous to a dict comprehension?

I imagine something like this:

>>> keys = "a b c".split()
>>> values = [1, 2, 3]
>>> D = dict([(a, b) for a, b in zip(keys, values)])
>>> D
{'a': 1, 'c': 3, 'b': 2}

Regards,
Ryan Ginstrom




More information about the Python-list mailing list