'How to slice a list based on its elements? [closed]
I have the following list
lst = [i for i in range(0, 1974, 47)]
I would like to slice it in a way to have: (0, 564), (564, 846), (846, 1128), (1128, 1410), (1410, 1692), and (1692, 1927).
I tried the following:
print(lst[0], lst[6*2])
for i in range(2, 7):
print(lst[6*i], lst[6*i+1])
I am expecting to hard code the first tuple and last one inside the for loop.
I tried manually the following:
h = [i for i in range(0, 1974, 47)]
print(h[0], h[6*2])
print(h[6*2], h[6*3])
print(h[6*3], h[6*4])
print(h[6*4], h[6*5])
print(h[6*5], h[6*6])
print(h[6*6], h[6*6+5])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
