Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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:
The simplest way to get theFinding index while handling the possibility of item x not being in list L:
The simplest way to get the index while handling the possibility of item x not being in list L:
pythonicThe simplest way to get the index while handling the possibility of item x not being in list L:
pythonic way to get the index while handling the possibility of item x not being in list L: