itertools.ilen?
Michael Peuser
mpeuser at web.de
Thu Aug 7 05:45:59 EDT 2003
Another solution could be to implement custom lenght methods. However I see
no graceful way to do it with the quite tricky implementation (yield is the
only hint!) of 2.3.
It would be definitly easy with 2.2 "by hand" function factories (def
iter(), def __next__()), just def len() in addition and find the fastest
implementation
Kindly
Michael
"Jeremy Fincher" <fincher.*@osu.edu> schrieb im Newsbeitrag
news:bgt56e$7no$2 at news.cis.ohio-state.edu...
> Michael Peuser wrote:
> > 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).
>
> But then, there's no way to determine whether any given class' __len__
will
> terminate, so you've got the same problem with len.
>
> Granted, it's more likely to manifest itself with iterators and ilen than
> with sequences and len, but if it's really an issue, ilen could take an
> optional "max" argument for declaring a counter ilen isn't to exceed.
>
> Jeremy
More information about the Python-list
mailing list