Python·100 questions

How does generator expression differ from list comprehension?

Answer
List comprehension creates a list immediately.
Generator expression creates items lazily.
Generator saves memory on large data.
Example: sum(x*x for x in data).
Generator can be “exhausted” once.
Was this answer helpful?

More questions in this topic

Related questions from other topics