For instance, if I wanted to cycle through a list and perform some operation on all but the final list entry, I could do this:
z = [1,2,3,4,2]
for item in z:
if item != z[-1]:
print z.index(item)
But instead of getting the output "...0 1 2 3," I'd get "...0 2 3."
Is there a way to perform an operation on all but the last item in a list (when there are IDENTICAL items in the list) without using a "for x in range (len(list) - 1)" sort of solution? I.e., I want to keep using "for item in list."
Many thanks!