Stop Saying Python Iterators Are Eager
A common misconception among developers is that Python iterators are inherently eager, requiring generators for lazy loading. However, custom iterators can be lazy without using generators, adhering to the iterator protocol. This can be demonstrated through a benchmark, showing that custom iterators can be used to stream data without loading all data upfront. This is particularly useful for large datasets or streaming data from external sources. To implement this, developers can create a custom iterator class that iterates over a data source without loading all data at once.