嵌套列表相减
a=[, , , , ]b=[, , , , ]
如何得出 [, , , , ]?
a=[, , , , ]
b=[, , , , ]
new_list = []
for i in range(len(a)):
temp = []
for j in range(len(a)):
temp.append(a-b)
new_list.append(temp)
print(new_list) Twilight6 发表于 2020-7-22 22:05
感谢
用列表推导式:
>>> a = [, , , , ]
>>> b = [, , , , ]
>>> [ for a, b in zip(a, b)]
[, , , , ] JoeJoy 发表于 2020-7-22 22:07
感谢
如果列表中的元素个数都是相同的,还可以这样用列表推导式:
a=[, , , , ]
b=[, , , , ]
new_list = [ -b for i in range(len(a))] for j in range(len(a))]
print(new_list) zltzlt 发表于 2020-7-22 22:08
用列表推导式:
{:10_245:}厉害,我都忘记可以用 zip 了 思维定式了
页:
[1]