lis=[["A","B",3],["C","D",4],["E","F",5]]
def search_and_increment(local_list,search):
for x in local_list:
if search in ",".join(x[:-1]):
x[-1]+=1
return
else:
local_list.append(search.split(",")+[1])
return
出力:
>>> search_and_increment(lis,"A,B")
>>> lis
[['A', 'B', 4], ['C', 'D', 4], ['E', 'F', 5]]
>>> search_and_increment(lis,"A,S")
>>> lis
[['A', 'B', 4], ['C', 'D', 4], ['E', 'F', 5], ['A', 'S', 1]]
>>> search_and_increment(lis,"A,S")
>>> lis
[['A', 'B', 4], ['C', 'D', 4], ['E', 'F', 5], ['A', 'S', 2]]
>>> search_and_increment(lis,"E,F")
>>> lis
[['A', 'B', 4], ['C', 'D', 4], ['E', 'F', 6], ['A', 'S', 2]]