我想在两个列表中找到分数
A=[2,3,5]
B=[6,7,0]
让分数减去2个数字。我如何定义分数,我可以通过索引I和j得到它的值?
:
score[0][1]=-5 which is 2-7=-5
或
score[1][2]=3 which is 3-0=3
我不知道怎么做!
双列表推导式很容易解决这个问题
A = [2, 3, 5]
B = [6, 7, 0]
score = [[i - j for j in B] for i in A]
print(score[0][1]) # -5
print(score[1][2]) # 3
整个score
数组
[[-4 -5 2]
[-3 -4 3]
[-1 -2 5]]