+ 1

Still I have no idea why would we use these "Generators" in Python ?

4th Apr 2020, 6:05 PM
Thushan Chamika
Thushan Chamika - avatar
3 Answers
+ 5
As an example, in case you need to read a huge file of data (let's say over 100 mb) you would use generators instead of saving the content files in a list. using generators saves a lot of memory due to the lazy evaluation and FIFO (first in first out). Even if you need certain data from the file, you still need to filter it somehow. Therefore you won't overload the memory with the entire content of the file at once. Theoretically generators can be of infinite values, so they can handle huge ammount of data. Another example is if you need to read a huge database and select only certain data from it. But this example refers to the same thing as the first one: lesser memory consumption.
5th Apr 2020, 12:17 AM
Sebastian Pacurar
Sebastian Pacurar - avatar
+ 3
Sebastian Pacurar Thank You very much !! That was so helpful đŸ™â€
5th Apr 2020, 7:00 AM
Thushan Chamika
Thushan Chamika - avatar
+ 2
Hello Thushan Chamika Which generators? And in which language? Please share more informations so that we can help you.
4th Apr 2020, 7:18 PM
Denise Roßberg
Denise Roßberg - avatar