Why does list.index throw an exception, instead of using an arbitrary value (for example, -1)? What\'s the idea behind this?
-1
To me it looks cleaner to d
Well, the special value would actually have to be None, because -1 is a valid index (meaning the last element of a list).
None
You can emulate this behavior by:
idx = l.index(x) if x in l else None