我可以通过使用列表索引来做到这一点......
lst =[1,2,3,4,5,6]
[ [lst[i] , lst[i+1]] for i in range( len(lst) - 1 )]
Run Code Online (Sandbox Code Playgroud)
要么:
lst =[1,2,3,4,5,6]
for i in range(len(lst)-1):
entities.append([lst[i],lst[i+1]])
Run Code Online (Sandbox Code Playgroud)
但是有更聪明的方法吗?也许使用迭代器?性能怎么样?