3 回答
TA贡献1796条经验 获得超7个赞
(代表问题作者发布解决方案,将其移至答案空间)。
我最终得到了一些工作:
final_list = []
for outer in range(len(a)):
for ele in range(len(a[outer])):
if ele == 0:
slice_start = 0
else:
slice_start += len(b[ele-1])
slice_end = len(b[ele])+slice_start
capture = [target for sublist in a[slice_start:slice_end] for target in sublist]
final_list.append(capture)
final_list = final_list[:len(a)]
绝对不如 heap_overflow 的答案漂亮。
TA贡献1836条经验 获得超3个赞
首先将您的子列表压缩到匹配对的列表中:
pair_list = [list(zip(a, b)) for a, b in zip(x, y) ]
结果:
[[(0, 'a'), (1, 'b'), (2, 'c'), (4, 'd')],
[(5, 'e'), (6, 'f'), (7, 'g'), (8, 'h')],
[(9, 'i'), (10, 'j'), (11, 'k'), (12, 'l')]]
现在,简单地展平内部列表。您可以将简单的展平视为“学生练习”,好吗?
添加回答
举报
