Skip to content
Advertisement

Tag: next

Getting next element while cycling through a list

When this reaches the last element, an IndexError is raised (as is the case for any list, tuple, dictionary, or string that is iterated). I actually want at that point for nextelem to equal li[0]. My rather cumbersome solution to this was Is there a better way of doing this? Answer After thinking this through carefully, I think this is

Advertisement