What would be the most pythonic way to convert a list like:
mylist = [0,1,2,3,4,5,6,7,8]
into fragments of n elements that always begin with the last element of the previous fragment. The last element of the last fragment must be identical to the first element of the first block to make the data structure circular. How:
[ [0,1,2,3], [3,4,5,6], [6,7,8,0], ]
under the assumption that len(mylist) % (n-1) == 0 . So it always works beautifully.
source share