我想重新排序python列表:
a = [1,2,3,4,5,6,7,...]
以下表格:
[[1,2,3],[2,3,4],[3,4,5],...]
最快的方法是什么?
答案 0 :(得分:1)
你可以尝试:
>>> 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]]