xiyanglxy
9/27/2019 - 4:21 AM

unique list of (list,tuple) #python #list #unique

unique list of (list,tuple) #python #list #unique

fruit=[('mango',3),('apple',2),('mango',2)]
fruit_df ={}
for i in fruit:
    if i[0] in fruit_df: #found
        fruit_df[i[0]]= (i[1]+fruit_df[i[0]])
    else:
        fruit_df[i[0]] = i[1]
print(fruit_df)