Is there an effective way to find the last matching item in a list? When working with strings, you can find the last element with rindex:
>>> a="GEORGE" >>> a.rindex("G") 4
... But this list does not exist for lists:
>>> a=[ "hello", "hello", "Hi." ] >>> a.rindex("hello") Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'list' object has no attribute 'rindex'
Is there a way to get this without creating a big loop? I would prefer not to use the inverse method if it can be avoided, since the order is important, and I also need to do some extra math to find out where the object / was / was. It seems wasteful.
Edit:
To clarify, I need the index number of this item.
python list
Kelketek Mar 23 2018-12-12T00: 00Z
source share