[Python-Dev] PEP 276 (simple iterator for ints)

Chermside, Michael mchermside at ingdirect.com
Wed Jun 30 16:31:51 EDT 2004


Andrew Koenig writes:
> I happened to look at PEP 276 and was struck by the thought 
> that PEP 276 is
> really an implementation of the well-known set-theoretic 
> construction of the
> natural numbers that defines each natural number as the set 
> of all smaller
> ones.  In other words, it defines 0 as the empty set, 1 as 
> the set whose
> only element is 0, 2 as the set whose elements are 0 and 1, and so on.

Interesting. I suppose that could be added as an extra argument
against those who claim that [0,1,2,3,4,5] is *NOT* the sequence
of integers "obviously" associated with the number 6. As for me,
even before I started using Python I had already become convinced
of that.

PEP 276 is worth a second look. In fact, it's trivial to
implement, and what it REALLY needs is a champion to bring it up
with the BDFL (and others).

Seriously, folks, replacing every one of these:

    >>> for i in range(len(myList)):
    ...     doSomethingWithIndexes(i)

with this:

    >>> for i in len(myList):
    ...     doSomethingWithIndexes(i)

is simple and elegant. And while at first glance it seems like
allowing iteration over ints would open up all kinds of subtle
bugs, I find that the PEP does a good job of arguing that it
doesn't.

-- Michael Chermside


This email may contain confidential or privileged information. If you believe you have received the message in error, please notify the sender and delete the message without copying or disclosing it.




More information about the Python-Dev mailing list