Performance Advantages to Iterators?

There’s actually a very good mail on the python mailing list about this: Iterators vs Lists. It’s a bit dated (from 2003), but as far as I know, it’s still valid.

Here’s the summary:

For small datasets, iterator and list based approaches have similar
performance.
For larger datasets, iterators save both time and space.

What I would draw from it is this: iterators are to be preferred over loading data into a list if possible. But unless you have a big dataset, don’t contort your code to make something that should fit in a list to work with an iterator.

Leave a Comment