I would like to reorder a python list:
a = [1,2,3,4,5,6,7,...]
to the following form:
[[1,2,3],[2,3,4],[3,4,5],...]
What is the fastest way to do that?
I would like to reorder a python list:
a = [1,2,3,4,5,6,7,...]
to the following form:
[[1,2,3],[2,3,4],[3,4,5],...]
What is the fastest way to do that?
you can try:
>>> a = [1,2,3,4,5,6,7]
>>> new_list = []
>>> for index in range(len(a)-2):
new_list.append(a[index:index+3])
>>> new_list
[[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7]]