Iterator vs Generator¶
Generator is a special case of Iterator.
Generator is easy and convenient to use but at additional cost (memory and speed).
If you need performance, use plain iterator (with the help of the itertools
module).
If you need convenience and concise code, use generator.
Please refer to Python Generator vs Iterator for more detailed discussions.