Skip to content

Tag: iterator

How to convert an iterable to a stream?

If I’ve got an iterable containing strings, is there a simple way to turn it into a stream? I want to do something like this: Answer Here’s my streaming iterator an experimental branch of urllib3 supporting streaming chunked request via iterables: Source with context: https://github.com/shazow/url…

Is enumerate in python lazy?

I’d like to know what happens when I pass the result of a generator function to python’s enumerate(). Example: Is the enumeration iterated lazily, or does it slurp everything into the <enumerate object> first? I’m 99.999% sure it’s lazy, so can I treat it exactly the same as the …

Get the first item from an iterable that matches a condition

I would like to get the first item from a list matching a condition. It’s important that the resulting method not process the entire list, which could be quite large. For example, the following function is adequate: This function could be used something like this: However, I can’t think of a good …