Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97096
| References | <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <00884c56-4c94-406b-9902-b94dda9d66b3@googlegroups.com> <201509242108.t8OL8wQs026851@fido.openend.se> |
|---|---|
| Date | 2015-09-25 07:49 +1000 |
| Subject | Re: Idiosyncratic python |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.148.1443131740.28679.python-list@python.org> (permalink) |
On Fri, Sep 25, 2015 at 7:08 AM, Laura Creighton <lac@openend.se> 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...
>>
>>--Ned.
>
> 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 :)
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Idiosyncratic python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-09-24 16:02 +1000
Re: Idiosyncratic python Paul Rubin <no.email@nospam.invalid> - 2015-09-23 23:16 -0700
Re: Idiosyncratic python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-09-24 16:35 +1000
Re: Idiosyncratic python Ben Finney <ben+python@benfinney.id.au> - 2015-09-24 16:54 +1000
Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 11:08 +1000
Re: Idiosyncratic python Terry Reedy <tjreedy@udel.edu> - 2015-09-24 02:54 -0400
Re: Idiosyncratic python wxjmfauth@gmail.com - 2015-09-24 00:06 -0700
Re: Idiosyncratic python Laurent Pointal <laurent.pointal@free.fr> - 2015-09-24 19:50 +0200
Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-24 21:05 +0100
Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 11:12 +0200
Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-24 14:09 +0100
Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 16:07 +0200
Re: Idiosyncratic python Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-24 08:26 -0600
Re: Idiosyncratic python Chris Angelico <rosuav@gmail.com> - 2015-09-25 02:57 +1000
Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 20:04 +0200
Re: Idiosyncratic python Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-24 12:19 -0600
Re: Idiosyncratic python Ned Batchelder <ned@nedbatchelder.com> - 2015-09-24 13:46 -0700
Re: Idiosyncratic python Laura Creighton <lac@openend.se> - 2015-09-24 23:08 +0200
Re: Idiosyncratic python Chris Angelico <rosuav@gmail.com> - 2015-09-25 07:49 +1000
Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 10:55 +1000
Re: Idiosyncratic python sohcahtoa82@gmail.com - 2015-09-24 15:32 -0700
Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-25 00:40 +0100
Re: Idiosyncratic python Akira Li <4kir4.1i@gmail.com> - 2015-09-25 03:04 +0300
Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 10:08 +1000
csiph-web