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.
Collections and Iterators in C++
Collections
-
Prefer
std::dequetostd::vectorwhen the size of the collection is unknow. -
Suppose set
AandBare two set with the same type and setCis another set with the same value type but a different comparison function, then it is still valid to insert …