Idiosyncratic python

Steven D'Aprano steve at
Fri Sep 25 03:08:11 CEST 2015

On Thu, 24 Sep 2015 04:54 pm, Ben Finney wrote:

> Steven D'Aprano <steve+comp.lang.python at> writes:
>> On Thursday 24 September 2015 16:16, Paul Rubin wrote:
>> > Steven D'Aprano <steve+comp.lang.python at> writes:
>> >> for k, v in mydict.items():
>> >>     del(k)
>> […] The obvious intent is to iterate over the *values* of the
>> dictionary, but the coder didn't know about values, so he iterated
>> over (key,value) pairs, then deleted the key local variable (not the
>> key in the dict!) to keep the namespace clean.
> That's not obvious to me. It's plausible, now that you say it. I find it
> also plausible, though, that the author is under the mistaken impression
> that the key and value must both be deleted, and has found a way that
> appears to do that.

In fairness, I have seen the rest of the loop, which I excised, and it uses
the value v. There's no hint that the author thinks the dict has been
cleared by the end of the loop.


More information about the Python-list mailing list