I have list that contains some repeatable elements.
And I want to find the index of the element starting from specific position (not from the start).
So I used index method on list object. According to documentation it has optional parameters start and stop.
Example of code I use:
lst = [5, 1, 2, 3, 4, 5, 6, 7]
index_5 = lst.index(5, start=2)
print(index_5)
And when I ran this code I got exception that index method doesn't have parameter start. What could be the problem?
Traceback (most recent call last):
File "D:/Misc.py", line 2, in <module>
index_5 = lst.index(5, start=2)
TypeError: index() takes no keyword arguments
As workaround I could make trick below, but if there's way to use language feature, I'd prefer it.
index_5 = lst[2:].index(5) + 2