0

What is iterator and generator?

plz give one example of iterator and generator

15th Dec 2017, 4:43 AM
lokesh reddy
lokesh reddy - avatar
3 Respuestas
+ 4
I assume you are referring to Python, so read this first; if you still have problems then feel free to ask. http://anandology.com/python-practice-book/iterators.html
15th Dec 2017, 4:54 AM
blackcat1111
blackcat1111 - avatar
+ 2
15th Dec 2017, 4:52 AM
John Wells
John Wells - avatar
0
Iterator it is special object in some of oop languages like java c# or python to iterate thru all elements of collection. For example java: ArrayList<> list = new ArrayList<int>(); Iterator it = list.getIterator(); while(it.hasNext()){doStuff(it.next());} will do Stuff for each element of list. Same in python: x=iter([1,2,3]) x.next() Generators it is a functions that return next element in some sequence java class seq {private int i=1; public int next() { int one = i++; return i+=i; }}
15th Dec 2017, 5:04 AM
Dima Makieiev
Dima Makieiev - avatar