How about:
len(a) - a[-1::-1].index("hello") - 1
Edit (put in function as suggested):
def listRightIndex(alist, value):
return len(alist) - alist[-1::-1].index(value) -1
Answer from EwyynTomato on Stack Overflow Top answer 1 of 4
22
How about:
len(a) - a[-1::-1].index("hello") - 1
Edit (put in function as suggested):
def listRightIndex(alist, value):
return len(alist) - alist[-1::-1].index(value) -1
2 of 4
10
This should work:
for index, item in enumerate(reversed(a)):
if item == "hello":
print len(a) - index - 1
break
W3Schools
w3schools.com โบ python โบ ref_string_rindex.asp
Python String rindex() Method
Remove List Duplicates Reverse ... Plan Python Interview Q&A Python Training ... The rindex() method finds the last occurrence of the specified value....
Python
bugs.python.org โบ issue36639
Issue 36639: Provide list.rindex() - Python tracker
April 16, 2019 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide ยท This issue has been migrated to GitHub: https://github.com/python/cpython/issues/80820
CSDN
devpress.csdn.net โบ python โบ 630464117e6682346619af34.html
Equivelant to rindex for lists in Python [duplicate]_python_Mangs-Python
August 23, 2022 - Answer a question Is there an efficient way to find the last matching item in a list? When working with strings, you can find the last item with rindex: >>> a="GEORGE" >>> a.rindex("G") 4 ...But this Mangs Python
Programiz
programiz.com โบ python-programming โบ methods โบ string โบ rindex
Python String rindex()
quote = 'Do small things with great love' # Substring is searched in ' small things with great love' print(quote.rindex('t', 2)) # Substring is searched in 'll things with' print(quote.rindex('th', 6, 20)) # Substring is searched in 'hings with great lov' print(quote.rindex('o small ', 10, -1))
GeeksforGeeks
geeksforgeeks.org โบ python-string-rindex-method
Python String rindex() Method - GeeksforGeeks
January 7, 2025 - Note: If start and end indexes are not provided then by default Python String rindex() Method takes 0 and length-1 as starting and ending indexes where ending indexes is not included in our search.
Javatpoint
javatpoint.com โบ python-string-rindex-method
Python String | rindex() method with Examples - Javatpoint
Python String rindex() method with Examples on capitalize(), center(), count(), encode(), find(), format(), index(), join(), lower(), ljust(), isupper(), istitle(), isspace(), isprintable(), isnumeric(), islower() etc.
Codecademy
codecademy.com โบ docs โบ python โบ strings โบ .rindex()
Python | Strings | .rindex() | Codecademy
October 6, 2023 - .rindex() is used to locate the highest index of the substring within a string variable.
W3Schools
w3schools.com โบ python โบ ref_list_index.asp
Python List index() Method
Python DSA Lists and Arrays Stacks Queues Linked Lists Hash Tables Trees Binary Trees Binary Search Trees AVL Trees Graphs Linear Search Binary Search Bubble Sort Selection Sort Insertion Sort Quick Sort Counting Sort Radix Sort Merge Sort
Jobtensor
jobtensor.com โบ Tutorial โบ Python โบ en โบ String-Methods-rindex
Python String rindex(), Definition, Syntax, Parameters, Examples | jobtensor
Python is a scripting language." result = testStr.rindex("t", 10, 25) print(result) # comparison between rindex() and rfind() testStr = "Welcome to the Python tutorials." print(testStr.rfind("x")) print(testStr.rindex("x"))
Tutorialspoint
tutorialspoint.com โบ python โบ string_rindex.htm
Python String rindex() Method
Python string method rindex() searches for the last index where the given substring str is found in an original string. This method raises an exception if no such index exists, optionally restricting the search to string length, i.e. from the ...
Rdrr.io
rdrr.io โบ cran โบ rindex โบ src โบ R โบ index.R
rindex source: R/index.R - rdrr.io
tab index EQual value \cr #! ... #! \code{\link{match.rindex}} \tab use this to match in an rindex instead of \code{\link[base]{match}} \cr #! } #! } #! \value{ #! An object of class \sQuote{index}, i.e. a list with components #! \item{val}{sorted vector of values} #! ...