Idiosyncratic python

Ben Finney ben+python at
Thu Sep 24 08:54:14 CEST 2015

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.

Perhaps what we're illustrating here is exactly why such idiosyncratic
code *is* bad: it obscures the intent of the code for programmers who
know idiomatic Python.

And those readers are hopefully the ones the author should be trying to
communicate to, on the theory that we've all got the goal to become a
programmer who knows idiomatic Python.

 \        “The fact of your own existence is the most astonishing fact |
  `\    you'll ever have to confront. Don't dare ever see your life as |
_o__)    boring, monotonous, or joyless.” —Richard Dawkins, 2010-03-10 |
Ben Finney

More information about the Python-list mailing list