Idiosyncratic python

Chris Angelico rosuav at
Thu Sep 24 23:49:02 CEST 2015

On Fri, Sep 25, 2015 at 7:08 AM, Laura Creighton <lac at> wrote:
> In a message of Thu, 24 Sep 2015 13:46:27 -0700, Ned Batchelder writes:
>>On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote:
>>> What are your favorite not-wrong-just-weird Python moments?
>>I've seen this a number of times:
>>    dict_of_values.update({'key': some_value})
>>why not:
>>    dict_of_values['key'] = some_value
>>I've considered writing a Pylint plugin to flag these...
> A student today had a similar version of this one:
> Every time he wanted to change the value of dictionary mapping he would
> write:
> w={'key': new_value}
> dict_of_values.update(w)

That's a new one on me! The oddest dictionary code any of my students
has come out with (so far!) was a slavish habit of always iterating
over them thus:

for k,v in some_dict.items():

where some_dict is the only part that changed. So everywhere through
the code - even in nested loops - all dictionary iteration used "k"
and "v".

But I suspect it's exactly the same. Saw some code somewhere, found
that it worked, used it. If you don't understand something, don't
change it... which is a good policy in general, I suppose :)


More information about the Python-list mailing list