姬長信(Redy)

平衡两个列表,直到它们的总和相等,并在Py…


a = [70, 30, 33, 23, 4, 4, 34, 95]
b = [50, 10, 10, 7]

我试过这个,但我知道这不够准确

if sum(a) > sum(b):
   a.sort()
   b.sort()
   temp = [int(i) for i in a]
   i=0
   while(sum(b)  sum(a):
    a.sort()
    b.sort()
    temp = [int(i) for i in b]
    i=0
    while(sum(a) 

结果是:

sums = 186,184

列表= [7,10,70,95,4],[4,10,23,30,33,34,50]

必填答案:

总和= 185,185

列表= [7,10,23,50,95],[4,4,10,30,33,34,70]