如果要从每个列表中删除最大元组,则:
In [17]: a=[(1,2),(4,5),(1,0)]
In [18]: a.remove(max(a, key=sum))
In [19]: a
Out[19]: [(1, 2), (1, 0)]
In [20]: b = [(3,2),(9,4),(2,2)]
In [21]: b.remove(max(b,key=sum))
In [22]: b
Out[22]: [(3, 2), (2, 2)]
或者如果你想从一个中删除最大元组并将其添加到下一个然后::
In [34]: a=[(1,2),(4,5),(1,0)]
In [35]: b = [(3,2),(9,4),(2,2)]
In [36]: b.append(a.pop(a.index(max(a,key=sum))))
In [37]: b
Out[37]: [(3, 2), (9, 4), (2, 2), (4, 5)]
In [38]: a
Out[38]: [(1, 2), (1, 0)]
或者如果你想从每个列表中删除 maxx 元组;然后将它们添加到另一个列表::
In [44]: maxx=[]
In [45]: a=[(1,2),(4,5),(1,0)]
In [46]: b = [(3,2),(9,4),(2,2)]
In [47]: maxx.append(a.pop(a.index(max(a,key=sum))))
In [48]: maxx.append(b.pop(b.index(max(b,key=sum))))
In [49]: a
Out[49]: [(1, 2), (1, 0)]
In [50]: b
Out[50]: [(3, 2), (2, 2)]
In [51]: maxx
Out[51]: [(4, 5), (9, 4)]