Terry Reedy <tjre...@udel.edu> wrote: > Vito De Tullio wrote: > > Tim Roberts wrote: > > > >> bearophileh...@lycos.com wrote: > >>> In Python 3 those lines become shorter: > >>> > >>> for k, v in a.items(): > >>> {k: v+1 for k, v in a.items()} > > This is nonsensical. It creates and discards a complete new dict for > each item in the original dict. The reuse of names 'k' and 'v' in the > comprehension just confuse.
You have to look back at the original post in which those lines appeared, and then look back further at the post which they were commenting on. Those two lines do not constitute consecutive lines of code, they are individual replacements for individual lines in two different previous examples, one of which updates the dict in place and the other of which creates a new dict. I think bearophile left out too much context :) -- R. David Murray http://www.bitdance.com -- http://mail.python.org/mailman/listinfo/python-list