how to get the ordinal number in list

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Aug 10 22:04:40 EDT 2014


Rustom Mody wrote:

> Its when we have variables that are assigned in multiple places that
> we start seeing mathematical abominations like
> x = x+1

That's not a mathematical abomination. It's a perfectly reasonable
mathematical equation, one with no solutions since the line f(x) = x and
the line f(x) = x+1 are parallel.

But what does this have to do with programming? Programming *is not*
mathematics, and x = x+1 has a different meaning in programming than in
mathematics. Perhaps it would help if we wrote it using mathematical
notation? Using [x] for subscripts:

x[n+1] = x[n] + 1

we have a perfectly good mathematical recursive definition. All it needs is
an initial value x[0] and we're good to go.



-- 
Steven




More information about the Python-list mailing list