Iterator length

Ben Finney bignose+hates-spam at
Thu Jan 18 20:10:54 EST 2007

bearophileHUGS at writes:

> But sometimes you don't need the elements of a given iterator, you
> just need to know how many elements it has.

AFAIK, the iterator protocol doesn't allow for that.

Bear in mind, too, that there's no way to tell from outside that an
iterater even has a finite length; also, many finite-length iterators
have termination conditions that preclude knowing the number of
iterations until the termination condition actually happens.

 \       "When a well-packaged web of lies has been sold to the masses |
  `\    over generations, the truth will seem utterly preposterous and |
_o__)                 its speaker a raving lunatic."  -- Dresden James |
Ben Finney

More information about the Python-list mailing list