A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-February/138376.html below:

[Python-Dev] Idea: __length_hint__ wrapper in itertools

[Python-Dev] Idea: __length_hint__ wrapper in itertools [Python-Dev] Idea: __length_hint__ wrapper in itertoolsCarlos Pita carlosjosepita at gmail.com
Thu Feb 19 18:15:32 CET 2015
Hi all,

python now supports the __length_hint__ method but not for every use
case that could potentially benefit from it, v.g.:

1) Some common builtins like map don't set the hint.
2) Generators.
3) Application specific hints that, by definition, can't be predicted
by a general strategy.

I know 1 and 2 were discussed at some length in the past, but still
there is no agreement about what to do with them.

In the meantime, and because of 3, what do you think about adding a
simple iterator wrapper to itertools which would allow to provide the
hint by the user without any significant performance lost (__next__ in
the wrapper could be just the original __next__). AFAIK there is no
such thing in the standard library or anywhere else and it seems
pretty easy to implement, although maybe I'm completely wrong.

Say:

hinted_iter = it.length_hint(iter, hint)

Cheers
--
Carlos
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4