PEP 276 Simple Iterator for ints (fwd)
jeff at ccvcorp.com
Thu Nov 29 02:56:12 CET 2001
Greg Ewing wrote:
> Jeff Shannon wrote:
> > David Eppstein wrote:
> > > I don't care for it -- is it really natural and intuitive
> > > that "x in y" should be equivalent to "0 <= x < y" when x and y are both
> > > ints?
> > PEP 276 does not make an integer equivalent to the
> > list of natural numbers ending below it;
> I think the point Mr. Eppstein was making is that
> "for i in seq" can be read as "for all values of i
> such that i in seq is true". PEP 276 would break
> that, because "for i in 5" couldn't sensibly be
> read as "for all values of i such that i in 5
> is true", unless "i in 5" on its own were valid and
> had a rather unintuitive meaning.
Okay, with this thought in mind, the comments do make much more sense. Though I
have to say, it would *never* have occurred to me to read a for-loop that way.
:) I also think that this interpretation of a for-loop is already broken with
iterators and generators, anyhow. If I have a generator that yields successive
values read from a serial port device, then the phrase "if i in serialinput()"
is meaningless (or, at best, useless), whereas the loop "for i in
serialinput():" makes perfect sense.
More information about the Python-list