[issue26828] Implement __length_hint__() on map() and filter() to optimize list(map) and list(filter)

Serhiy Storchaka report at bugs.python.org
Fri Apr 22 08:49:57 EDT 2016


Serhiy Storchaka added the comment:

See also issue14126.

It makes sense to implement map.__length_hint__() and  zip.__length_hint__(). But note that map() and zip() take several iterables, and we should call __length_hint__() for every of them (unless found a one with not implemented __length_hint__()). This can slow down the execution for short sequences.

It is impossible to implement reasonable filter.__length_hint__(), because the length of resulting sequence can be from 0 to the length of the input sequence, and returning the maximal value would be not correct.

----------
nosy: +rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26828>
_______________________________________


More information about the Python-bugs-list mailing list