I'm having Python 2.7 in my system. I'm also trying to de-deuplicate a lit of lists and join the values of the duplicates. Let my list be:
original_list = [['a', 1], ['b', 1], ['a', 1], ['b', 1], ['b', 2], ['c', 2], ['b', 3]]
I need to coordinate on the principal component of each settled rundown and afterward add the estimations of the subsequent component. I need to wind up with this (the request for the last rundown doesn't make a difference):
ideal_output = [['a', 2], ['b', 7], ['c', 2]]
Look at the following code, which will find the duplicate values based on the first element of each nested list:
for item in original_list:
matches = -1
for x in original_list:
if (item[0] == x[0]):
matches += 1
if matches >= 1:
if item[0] not in duplicates_list:
duplicates_list.append(item[0])
Can anyone suggest what would be the best way to find the duplicates?