If I have list of tuples like this:
my_list = [(\'books\', \'$5\'), (\'books\', \'$10\'), (\'ink\', \'$20\'), (\'paper\', \'$15\'), (\'paper\', \'$20\'), (\'pap
This is fairly easy using a dictionary:
result={} #initialize an empty dictionary
for (type,cost) in my_list:
if type not in result.keys():
result[type]=int(cost[1:]) #add entry
else:
result[type]=result[type]+int(cost[1:]) #increment cost
#make dictionary a list again
dictlist=[]
for key, value in result.iteritems():
temp = [key,"$"+str(value)] #add dollar sign
dictlist.append(temp)
print dictlist
Edit: forgot two lines