PEP 276 Simple Iterator for ints
Lulu of the Lotus-Eaters
mertz at gnosis.cx
Wed Nov 28 21:58:23 CET 2001
David Eppstein <eppstein at ics.uci.edu> wrote:
|The latter notation now seems unnecessarily redundant. Think of it by
|analogy -- which of the following would you most likely use,
| if 0 <= i < 5:
|or
| if i in [0, 1, .. 4]:
|or
| if i in range(5):
|or even (with Perl-like conciseness)
| if i in 5:
I think this is wrong--the "redundant" part, that is. These forms, at
first brush, have very different meanings from each other.
In a hypothetical Python++ that had all the variations implemented, they
would have a different range of application:
>>> i = 2; j = 3 # want an even Natural number less than 100...
>>> if 0 < i < 100: print 'even Natural'
...
even Natural
>>> if 0 < j < 100: print 'even Natural' # gives wrong answer
...
even Natural
>>> if i in [2,4 .. 98]: print 'even Natural'
...
even Natural
>>> if j in [2,4 .. 98]: print 'even Natural' # gives correct answer
...
>>> if i in 100: print 'even Natural' # I have no idea what this MEANS!
...
?????
Those are step-size issues. But even with step-sizes of one, a similar
problem comes up:
>>> x = 3.5
>>> if 0 <= x < 5: print 'in range [0 .. 5)'
...
in range [0 .. 5)
>>> if x in [0,1 .. 4]: print 'in range [0 .. 5)'
...
>>> if x in 5: print 'in range [0 .. 5)' # No idea what this MEANS!
...
?????
Given the BDFL's goal of Int/Float/Rational unification in some
far-future, the integer-only 'min <= x < max' syntax looks particularly
bad.
Yours, Lulu...
More information about the Python-list
mailing list