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::deque
tostd::vector
when the size of the collection is unknow. -
Suppose set
A
andB
are two set with the same type and setC
is another set with the same value type but a different comparison function, then it is still valid to insert …