11 Oct
2021
11 Oct
'21
3:27 a.m.
Chris Angelico writes:
Using popitem mutates the underlying dict. That's a tad more likely to affect other parts of the code.
Granted. The context is opposition to itertools.first. "Advocating" popitem is tongue-in-cheek, with the serious point is that it's obvious that it alters state from the name (at least if you have any knowledge of data structures). You can restore the state trivially (OK, race condition, yadda yadda). Neither is true of itertools.first. It's neither obviously destructive from the name, nor is it necessarily possible to restore state.