你可以这样做:
a_list=[[1,15],[2,17]]
b_list=[[1,1],[3,4],[5,9]]
for a in a_list:
found = False
for b in b_list:
if a[0] == b[0]:
b[1] += 1
found = True
if not found:
b_list.append([a[0],1])
print(a_list)
print(b_list)
输出:
[[1, 15], [2, 17]]
[[1, 2], [3, 4], [5, 9], [2, 1]]