I'd like a minor clarification of the topic at: How to slice a list from an element n to the end in python?
I want to slice a list inside a loop, so that the last iteration of the loop includes the last element of the list. The only way I've found to do this so far (based on the answers in the other thread) is as follows:
>>> x = list(range(1,11))
>>> for i in range(0,4):
... x[i:-3+i if -3+i != 0 else None]
The values of x that I expect in each iteration are:
[1, 2, 3, 4, 5, 6, 7]
[2, 3, 4, 5, 6, 7, 8]
[3, 4, 5, 6, 7, 8, 9]
[4, 5, 6, 7, 8, 9, 10]
It works, but is my solution really the most Python-esque way to accomplish this?