lst = [[1, 5],
[2, 2]
这是我的嵌套列表,我需要将其制作成点形式的列表:
- 第一层 - 第二层 A 点 - 第二层 B 点 - 第一层 C 点 - 第一层 D 点
output = [[1, 5, 2, 2]
这是我的尝试,对于这种情况它可以工作,但如果我有一个行长度为6或大于4的例子,它就会失败。
new_lst = []
for x in range(len(lst)):
for y in range(0, len(lst[x]), 2):
new_lst.append([lst[x][y],lst[x][y+1]])
counter_a = 0
counter_b = 1
output = []
while counter_b - 4 <= len(lst):
output.append(new_lst[counter_a] + new_lst[counter_a + 2])
output.append(new_lst[counter_b] + new_lst[counter_b + 2])
counter_a += 4
counter_b += 4
print(output)