Q. Why use lazy iterators?
A. To solve memory issue. use the yield
keyword instead or return
inside functions
E. Reading a list of large files (~GB) into python list
can cause memory issue, so return a lazy iterator, or generator in python, which will lazy load these things when they are needed.
Q. What does generator consists of?
A. some metadata like state of the function, variable binding, instruction pointer, internal stack etc.
For detailed instruction, this link has a good example.