fencepost

What is the pythonic way to detect the last element in a 'for' loop?

What is the pythonic way to detect the last element in a 'for' loop? Question: How can I treat the last element of the input specially, when iterating with a for loop? In particular, if there is code that should only occur "between" elements (and not "after" the last one), how can I structure the …

Total answers: 34