Indentifying the LAST occurrence of an item in a list

mkPyVS mikeminer53 at hotmail.com
Thu Apr 5 14:55:30 EDT 2007


Not sure below is better but it hacks at larger chunks (excuse the 10
second coding)
m = [2,9,1,5,6,3,1,1,9,2]
f = 1
temp = m
location = m.index(f)
gloc = location
temp = m[location:]
while 1:
   print(temp)
   try:
      location = temp.index(f) + 1
      gloc += location
   except:
      break
   temp = temp[location:]
#Remove the last 0th element
gloc -= 1
print("Last location = %d" % gloc)




More information about the Python-list mailing list