On 7/26/2019 6:05 PM, Kyle Stanley wrote:
Andrew Barnert wrote:
consume(print(item) for item in lst)
From my understanding, consume() effectively provides the functionality the
author was looking for. Also, between the options of `for _ in iter:` vs
`colllections.deque(it, maxlen=0)`, how significant is the performance
difference?
I had assumed that the performance of `for _ in iter` would be significantly
better, since due to the overhead cost of creating and filling a double ended
queue,
which provides optimization for insertion at the beginning and end. Wouldn't a
one
directional iterator provide better performance and have a lower memory cost if
there is no modification required?
I haven't run any numbers. But moving a loop from Python code to C code
is almost always a win. That's what's happening here. And I think the
idea is a that deque with 0 members doesn't have much overhead.
Eric
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/WNZKN7OGCTPN6AKRG5TG3IL6BXZRHNNE/
Code of Conduct: http://python.org/psf/codeofconduct/