Oct-11-2020, 01:30 AM
Maybe not the most standard way, but I would use compress and cycle here to create two iterators for the front and the back.
from itertools import cycle, compress n = 32 front = compress(range(1,n+1), cycle([1]*4 + [0]*4)) rear = compress(range(1,n+1), cycle([0]*4 + [1]*4)) print(f"front: {list(front)}") print(f"rear: {list(rear)}")
Output:front: [1, 2, 3, 4, 9, 10, 11, 12, 17, 18, 19, 20, 25, 26, 27, 28]
rear: [5, 6, 7, 8, 13, 14, 15, 16, 21, 22, 23, 24, 29, 30, 31, 32]