Making a dict from two lists/tuples

Gareth McCaughan Gareth.McCaughan at pobox.com
Thu May 24 17:31:00 EDT 2001


John Carter wrote:

> result = [{k: v} for k, v in zip(keys, values)]

and then, rightly, recanted on the grounds that this
does the Wrong Thing. But, hmmm, how come we don't
have dictionary comprehensions?

result = { k:v for k,v in zip(keys, values) }

<0.5 wink>

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
.sig under construc



More information about the Python-list mailing list