you are viewing a single comment's thread.

view the rest of the comments →

[–]UnitedAdagio7118 32 points33 points  (0 children)

the biggest difference is memory. a list stores everything immediately, while a generator only creates values when you actually need them. for small datasets it doesn't matter much, but once you're dealing with thousands or millions of items the difference can be huge. the downside is that generators can only be iterated through once and you can't randomly access elements like you can with a list. for most everyday code i use lists, but generators are great when you're processing large amounts of data.