Waffling (was Re: single-line terinary operators considered harmful)
Stephen Horne
intentionally at blank.co.uk
Thu Mar 6 14:28:19 EST 2003
On Thu, 6 Mar 2003 13:03:50 -0700, Steven Taschuk
<staschuk at telusplanet.net> wrote:
>Certainly Python's guaranteed evaluation and execution order is
>very comfortable. There is the occasional oddity:
> d = {}
> i = 3
> i = d[i] = i+1
>has a surprising (to me) result. But this isn't good style anyway.
I wondered what you were talking about - until I noticed that...
>>> d={}
>>> i=3
>>> i=d[i]=i+1
>>> i
4 <- this was expected
>>> d[i]
4 <- this was expected
>>> d
{4: 4} <- pardon? - why not {3: 4}
I'm not sure I understand it, but I imagine it has to do with '='
being n-ary (n >= 2) non-associative (rather than binary
right-associative). Maybe the assigns are done left-to-right, even
though the rightmost item is the source and must be evaluated first?
--
steve at ninereeds dot fsnet dot co dot uk
More information about the Python-list
mailing list