3 ms·
TBH I'm surprised that even works in Python – modifying a collection you're in the middle of iterating seems like a bad habit to get into in any language. edit
by msbarnett 4y ago
TBH I'm surprised that even works in Python – modifying a collection you're in the middle of iterating seems like a bad habit to get into in any language.
edit: in fact, if you specifically use a deque in Python the way you are in Rust, Python will throw a "RuntimeError: deque mutated during iteration". This is just a bad approach in any language, honestly.
- duped 4y agoAgreed, python may be a contrived example here. It is possible to pull this off in a few languages where object relocation isn't a problem and mutating a collection during iteration is natural.