[Python-ideas] Reference variable in assignment: x = foo(?)

Corey Sarsfield subbarker at gmail.com
Thu Jul 11 23:07:07 CEST 2013


I came up with the idea after having some code on dicts that looked like:

a[b][c] = foo(a[b][c])

So in this case there are twice as many look-ups going on as there need to
be, even if a[b][c] were to be pulled out into x.

If I were to do:

a[b][c] += 1

Would it be doing the lookups twice behind the scenes?


On Thu, Jul 11, 2013 at 4:00 PM, R. Michael Weylandt <
michael.weylandt at gmail.com> wrote:

> On Thu, Jul 11, 2013 at 3:39 PM, Corey Sarsfield <subbarker at gmail.com>
> wrote:
> > I've always found +=, -= and the like to be handy, but I had hoped like
> so
> > many other things in python there would be a generic form of this
> > functionality.
> >
> > x += 5 could be expressed as x = ? + 5 perhaps.
> >
> >
>
> Can you flesh this out a bit further? Isn't x += 5 <--> x = x + 5
> already defined unless a class specifically does something funny with
> __iadd__?
>
> Cheers,
> Michael
>



-- 
Corey Sarsfield
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130711/d5f0187c/attachment-0001.html>


More information about the Python-ideas mailing list