Process tuple contents on the fly
MRAB
python at mrabarnett.plus.com
Mon Apr 15 15:29:47 EDT 2013
On 15/04/2013 20:05, Barrett Lewis wrote:
>
>
>
> d = {}
> for key, d[key] in (("this",18), ("that",17), ("other",38)):
> print key
> do_something(d)
>
>
> Why not use a dict comprehension?
> d = {k:v for k,v in (("this",18), ("that",17), ("other",38))}
>
> I feel this is more straightforward and easier to read. the results are
> the same however.
>
Why use a dict comprehension? :-)
d = dict((("this",18), ("that",17), ("other",38))}
More information about the Python-list
mailing list