10 Answers
+ 11
You may look this 1 also. If something is unclear then you can ask us
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2462/?ref=app
+ 11
here is a commented code showing an example where generators and yield are used:
https://code.sololearn.com/cOGvT24D3Of9/#py
+ 5
Ana generators can used for anything you like. Generators make it easier to code methods that create, modify and return list like structures. Also those yielded values are iterable and you can use those values in for loops.
+ 5
for i in range(1,10,3)
can be seen as easy generator.
even not in python sense.
sometimes the rules to get the numbers are complicated and separared in a generators (fibonaccis maybe)
also a loop is not always wanted.
generators can help to avoid them.
+ 4
SΔηÎčrÏ
Ïαsαη, okey, thank u)
+ 2
Hey Ann, yield statements are useful when you want to conserve memory. If you use a print statement or a for or while loop, there will be no pause (unless you ask for input after each result is displayed) between each result. Alternately you could place all results in some sort of data structure but this can slow down the computer as it uses more RAM. The yield statement will only display one result at a time.
+ 1
How often generators will be used?
+ 1
They look highly useful. It is very common for computers to create lists and then to want to count (iterate) through them. Maybe you have a class full of students, or maybe a fleet of trucks, or maybe 300 orders from a web site, or a full day of temperature readings from a sensor that took a reading every minute.
0
who wants to solve problems
0
ŰȘŰš