获取在python中操作原始列表的多维列表

我想根据磁贴分组文件列表.

files = ['tile1_band1','tile1_band2','tile2_band1','tile2_band2']
tiles = [file[0:5] for file in files]
for tile in tiles:
    new_files = [file for file in files if tile in file]
    print (new_files)

结果应完全如下(二维列表):

[['tile1_band1', 'tile1_band2'], ['tile2_band1', 'tile2_band2']]

最佳答案 使用
zip builtin并在切片中放一步:

In [26]: a = range(10)

In [27]: zip(a[::2], a[1::2])
Out[27]: [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]
点赞