[Solved] Python count list and types [closed]


newlist = []
for sublist in yourlist:
    already_in_list = False
    for index, newsublist in enumerate(newlist):
        if sublist == newsublist[:-1]:
            newlist[index][2] += 1
            already_in_list = True
    if not already_in_list:
        newlist.append(sublist+[1])

>>>newlist
[['personA', 'banana', 1], ['personB', 'banana', 2], ['personA', 'grape', 1], ['personA', 'lemon', 2]]

solved Python count list and types [closed]