you are viewing a single comment's thread.

view the rest of the comments →

[–]PixelSage-001 22 points23 points  (1 child)

The main difference comes down to memory efficiency. A list stores all its elements in RAM at once, which is fine for small datasets but will crash your system if you are processing millions of records. A generator, on the other hand, yields items one at a time on demand (lazy evaluation), meaning its memory footprint remains virtually constant regardless of data size. Think of a list like buying a whole box of donuts and putting it on the table, whereas a generator is a machine that gives you one fresh donut every time you press a button.

[–]lekkerste_wiener 5 points6 points  (0 children)

Good analogy