Skip to main content
deleted 8 characters in body
Source Link
Ketan
  • 1.5k
  • 14
  • 16

Finding index of item xx in list LL:

idx = L.index(x) if (x in L) else -1 

Finding index of item x in list L:

idx = L.index(x) if (x in L) else -1 

Finding index of item x in list L:

idx = L.index(x) if (x in L) else -1 
deleted 61 characters in body
Source Link
Ketan
  • 1.5k
  • 14
  • 16

The simplest way to get theFinding 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 

Finding index of item x in list L:

idx = L.index(x) if (x in L) else -1 
added 2 characters in body
Source Link
Ketan
  • 1.5k
  • 14
  • 16

pythonicThe 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 

pythonic 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 
deleted 4 characters in body
Source Link
Ketan
  • 1.5k
  • 14
  • 16
Loading
Source Link
Ketan
  • 1.5k
  • 14
  • 16
Loading