+ 1
Still I have no idea why would we use these "Generators" in Python ?
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.
+ 3
Sebastian Pacurar Thank You very much !! That was so helpful đâ€
+ 2
Hello Thushan Chamika
Which generators? And in which language?
Please share more informations so that we can help you.