itertools.ilen?

Michael Peuser mpeuser at web.de
Thu Aug 7 10:35:59 CEST 2003


"Terry Reedy" <tjreedy at udel.edu> schrieb im Newsbeitrag
news:tpKdnUQ75tjOZKyiU-KYuQ at comcast.com...
>
> "Jeremy Fincher" <fincher.*@osu.edu> wrote in message
> news:bgsqj5$228$1 at news.cis.ohio-state.edu...
> > Sometimes I find myself simply wanting the length of an iterator.
>
> An iterator is a function/method that traverses (or possibly
> generates) a seqeuence.  The sequence has a length (actual or
> potential) but the iterator does not.
>

Very well explained. There are lots of usefull generators with unlimited
sequences.

- random generators

- def achilles():
        while 1
               :N=1.
               yield N
               n=n/2

- def schoenberg():
       cycle=range(12)
       while 1:
             shuffle(cycle)
             for i in cycle:
                  yield i


There is no way to determined, whether such generartors will  come to an
end - The Halting Problem for Turing Machines  ;-)
Thus there will never be a safe len(iterator).

Kindly
Michael






More information about the Python-list mailing list