What is the difference between iterator and generator? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between iterator and generator?

Can you help me

22nd Apr 2020, 3:49 PM
Aakash Agrawal
Aakash Agrawal - avatar
3 Answers
+ 2
Generator gives us a sequence of values to iterate upon wheras an iterator returns us an iterator object- one value at a time. Go here for detailed information 👇 https://data-flair.training/blogs/python-generator-vs-iterator/
22nd Apr 2020, 3:55 PM
Arsenic
Arsenic - avatar
+ 2
it is much easier to use generators function to create iterators because they simplify their creation, but a custom Iterator gives you more freedom and you can also implement other methods according to your requirements
22nd Apr 2020, 4:08 PM
Arsenic
Arsenic - avatar
0
But a sequence can be converted to iterator by iter than why to use generation
22nd Apr 2020, 3:57 PM
Aakash Agrawal
Aakash Agrawal - avatar