PEP 424 __length_hint__() - Is there a way to do the same for generators or zips?
问题 Just came across this awesome __length_hint__() method for iterators from PEP 424 (https://www.python.org/dev/peps/pep-0424/). Wow! A way to get the iterator length without exhausting the iterator. My questions: Is there a simple explanation how does this magic work? I'm just curious. Are there limitations and cases where it wouldn't work? ("hint" just sounds a bit suspicious). Is there a way to get the hint for zips and generators as well? Or is it something fundamental only to iterators?