4 ms·
> If you’re using Python, you’re stuck with the endless debates. For instance, you’ll never know why there’s a dict.get() to avoid KeyError but no list.get() to
by mayoff 2y ago
> If you’re using Python, you’re stuck with the endless debates. For instance, you’ll never know why there’s a dict.get() to avoid KeyError but no list.get() to avoid IndexError.
Probably for the same reason that, in Swift, dictionary lookup returns an Optional but Array traps on out-of-bounds: dictionary keys tend to come from outside the dictionary, but array indices tend to be derived from the array bounds. This means a dictionary lookup failure tends to be expected, and an out-of-bounds array index tends to be a logic error. More details here: https://stackoverflow.com/a/75780575/77567 https://stackoverflow.com/a/75780575/77567