Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 10)
10.
What is the main difference between a generator and a list comprehension?
Generators are used for creating lists, while list comprehensions produce iterators
List comprehensions create lists in memory, while generators produce values on-the-fly
List comprehensions can only be used with numerical data, while generators work with any data type
Generators use the list() constructor, while list comprehensions use generator()
Answer: Option
Explanation:
List comprehensions create lists in memory, whereas generators produce values on-the-fly and do not store the entire sequence in memory. Generators are more memory-efficient.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.