例如:
a=[123,456]
b=[789,345]
需要完成的操作是(1-7)+(2-8)+(3-9)+(4-3)+(5-4)+(6-5)
,并且应该返回总计数。
答案 0 :(得分:1)
您可以使用zip
:
a=[123,456]
b=[789,345]
a1 = ''.join(map(str, a))
b1 = ''.join(map(str, b))
final_sum = sum(c-d for c, d in zip(map(int, list(a1)), map(int, list(b1))))
答案 1 :(得分:0)
a=[123,456]
b=[789,345]
total = 0
for aa,bb in zip(a,b):
for aaa,bbb in zip(str(aa), str(bb)):
total += int(aaa) - int(bbb)
print (total)