LookupError is the parent of both KeyError and IndexError. Write lookup(container, key) that returns container[key] and classifies failures into 'key-miss' (KeyError), 'index-miss' (IndexError), or 'other-lookup' (any other LookupError) — and get the except order right, because putting the parent first would shadow the children.lookup({'a': 1}, 'z')'key-miss'
Dict lookups raise KeyError.
lookup([1, 2], 9)
'index-miss'
List lookups raise IndexError.
Most-specific exceptions must come first.
The bare LookupError clause is the safety net.