The simplest way to get the index while handling the possibility of item x not being in list L:
idx = L.index(x) if (x in L) else -1 The simplest way to get the index while handling the possibility of item x not being in list L:
idx = L.index(x) if (x in L) else -1