LINUX.ORG.RU

История изменений

Исправление Novator, (текущая версия) :

Я бы сделал так:

a = [(0,10.8),(1,8.2),(2,0.3)]
b = [(0,0.4),(3,20.2),(2,0.3)]

c = list(a)
ind1 = 0
for elem in c:
  key1 = elem[0]
  ind2 = next(i for i, e in enumerate(b) if e[0] == key1)
  if not(ind2 is None):
    c[ind1] = (key1, elem[1]+b[ind2][1])
  ind1 += 1

c = sorted(c, key=lambda x: x[1], reverse=True)

Исправление Novator, :

Я бы сделал так:

a = [(0,10.8),(1,8.2),(2,0.3)]
b = [(0,0.4),(3,20.2),(2,0.3)]

c = list(a)
ind1 = 0
for elem in c:
  key1 = elem[0]
  ind2 = next(i for i, e in enumerate(b) if e[0] == key1)
  if not(ind2 is None):
    c[ind1] = (key1, elem[1]+b[ind2][1])
  ind1 += 1

sorted(c, key=lambda x: x[1], reverse=True)

Исходная версия Novator, :

Я бы сделал так:

a = [(0,10.8),(1,8.2),(2,0.3)]
b = [(0,0.4),(3,20.2),(2,0.3)]

c = list(a)
for elem in c:
  ind1 = elem[0]
  ind2 = next(i for i, e in enumerate(b) if e[0] == ind1)
  if not(ind2 is None):
    c[ind1] = (ind1, elem[1]+b[ind2][1])

sorted(c, key=lambda x: x[1], reverse=True)