Python 101 : Generators and Lists
A list is a collection of values stored in memory.
A generator does not build a list, it only tells us how to generate these values with nothing stored in memory.
Our examples below use the "range()" iterator and they produce the same results.
Below is our list example:
The generator expression generate values only when they are needed which saves us system resources, especially with huge amounts of data.
Comments
Post a Comment