[Python-Dev] PEP 0424: A method for exposing a length hint

Stefan Behnel stefan_ml at behnel.de
Mon Jul 16 08:54:27 CEST 2012

Mark Shannon, 15.07.2012 16:14:
> Alex Gaynor wrote:
>> CPython currently defines an ``__length_hint__`` method on several types,
>> such
>> as various iterators. This method is then used by various other functions
>> (such as ``map``) to presize lists based on the estimated returned by
> Don't use "map" as an example.
> map returns an iterator so it doesn't need __length_hint__

Right. It's a good example for something else, though. As I mentioned
before, iterators should be able to propagate the length hint of an
underlying iterator, e.g. in generator expressions or map(). I consider
that an important feature that the protocol must support.


More information about the Python-Dev mailing list