python find the position of the last value of the repeated element in the list

If you replace this problem with finding the position of the first value, you can use list.index(value) to find it, and it’s okay to use enumerate:

def unique_index(L,e):
    return [j for (i,j) in enumerate(L) if i == e]

Since we are looking for the position of the last occurrence, a simpler approach can be taken. Just reverse the list and find the first element.
write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325900976&siteId=291194637
Recommended