how to get the ordinal number in list

Chris Angelico rosuav at gmail.com
Mon Aug 11 01:46:25 EDT 2014


On Mon, Aug 11, 2014 at 3:23 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> A C programmer asked to swap variables x and y, typically writes something like
>
> t = x; x = y; y = t;
>
> Fine, since C cant do better.
> But then he assumes that that much sequentialization is inherent to the problem...
> Until he sees the python:
>
> x,y = y,x
>
> The same applies generally to all programmers brought up on imperative style.

Uhh, that's still imperative. There is a chronological boundary here:
prior to that statement's execution, x and y have certain values, and
after it, they have the same values but the other way around. When
you're manipulating algebraic statements, moving down the page doesn't
correspond to any sort of time change, which is why "x = x + 1" has no
solutions.

Please explain to me how "x,y = y,x" is materially different from "x =
x + 1" in that the latter is, in your words, an abomination, but you
say the former doesn't have the same problem.

ChrisA



More information about the Python-list mailing list