0
What is iterator and generator?
plz give one example of iterator and generator
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
+ 2
Please read this so you can ask better questions.
https://www.sololearn.com/Discuss/333866/?ref=app
You don't say what language you want the answer for.
JavaScript:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators
Python:
http://zetcode.com/lang/python/itergener/
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;
}}