[Python-Dev] Idea: length_hint wrapper in itertools (original) (raw)
Carlos Pita carlosjosepita at gmail.com
Thu Feb 19 18:15:32 CET 2015
- Previous message: [Python-Dev] [Python-checkins] cpython (3.4): Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
- Next message: [Python-Dev] Idea: __length_hint__ wrapper in itertools
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi all,
python now supports the length_hint method but not for every use case that could potentially benefit from it, v.g.:
- Some common builtins like map don't set the hint.
- Generators.
- 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
- Previous message: [Python-Dev] [Python-checkins] cpython (3.4): Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integer
- Next message: [Python-Dev] Idea: __length_hint__ wrapper in itertools
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]