Skip to main content
3 of 5
added 2 characters in body
Ketan
  • 1.5k
  • 14
  • 16

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 
Ketan
  • 1.5k
  • 14
  • 16