I need to do some special operation for the last element in a list. Is there any better way than this?
array = [1,2,3,4,5]
for i, val in enumerate(array):
if (i+1) == len(array):
// Process for the last element
else:
// Process for the other element
enumerateto do pretty much the same thing in the link you gave. He's asking for a better and more pythonic way to detect the last element, rather than using the approach he listed. Should not be considered a duplicate.