[Python-Dev] PEP 0424: A method for exposing a length hint (original) (raw)

Ethan Furman ethan at stoneleaf.us
Mon Jul 16 21:59:20 CEST 2012


M Stefan wrote:

Also, what would iter([1,2,3]).lengthhint() return? 3 or unknown? If 3, then the semantics of l=[1,2,3]; l += iter(l) will change (infinite loop without lengthhint vs. list of 6 elements with lengthhint).

What length_hint returns is irrelevant -- it's only a hint. Python will have to loop over all the items. So you would still get an infinite loop with the above code.

Ethan



More information about the Python-Dev mailing list