Q:

Python list sum elements

I have this list in Python:
[['jhidalgo', 19, u'6,8'],
['jhidalgo', 19, u'5,3'],
['jhidalgo', 20, u'7'],
['jhidalgo', 20, u'0,4'],
['jhidalgo', 20, u'0'],
['jhidalgo', 20, u'1,6'],
['jhidalgo', 21, u'6,9'],
['jhidalgo', 22, u'1,3'],
['jhidalgo', 23, u'6,9'],
['jtern', 19, u'6,9'],
['jtern', 19, u'3,2']
]

I need to sum numbers after u letter in case if two previous elements are the same:
  ['jhidalgo', 19, u'6,8'],
  ['jhidalgo', 19, u'5,3'],

These two strings have two identical elements: jhidalgo and 19.  So we could sum numbers after the u letter: 6,8 + 5,3 = 12,1
How can I get a list like this? 
[['jhidalgo', 19, u'12,1'],
['jhidalgo', 20, u'9'],
['jhidalgo', 21, u'6,9'],
['jhidalgo', 22, u'1,3'],
['jhidalgo', 23, u'6,9'],
['jtern', 19, u'10,1']
]

I need to sum the third element by grouping the second and first element.  For example, all the jhidalgo with 20...the sum is 7+0.4+0+1.6 = 9

A:

Assuming that the values are intended to interpret commas as decimal points, and that all values to be grouped are consecutive, you can use itertools.groupby to good effect here:
import itertools
from math import fsum
from operator import itemgetter

mylist = [...]

summed = [(name, num, fsum(float(x.replace(',', '.'))  for x in g))
          for (name, num), g in itertools.groupby(mylist, key=itemgetter(0, 1))]

Using groupby is the best solution if the data is already consecutive by key (and preserves order without difficulty), but if the values to be grouped are not consecutive, you can either sort (by the same key used for groupby), e.g. running mylist.sort(key=itemgetter(0, 1)) before computing summed with groupby as above, or to avoid O(n log n) sort costs, you can use a dict (or for simplicity, defaultdict(float)) to group non-consecutive groups:
from collections import defaultdict

sumdict = defaultdict(float)
for name, num, val in mylist:
    sumdict[name, num] += float(val.replace(',', '.')) 

# Side-note: I'd have used tuple/namedtuple for the triples here since the data likely
# shouldn't be mutable, and tuples are the "proper" type for fixed length,
# heterogeneous, immutable data, but the functional difference is minimal
summed = [[name, num, valsum] for (name, num), valsum in sorted(sumdict.items())]

A:

You can use pandas, It's a great python module for data analysis. 
Or:
# sorting
d = {}
for name, value, amount in l:
    if (name, value) not in d:
        d[name, value] = 0
    d[name, value] += float(amount.replace(',', '.')) 

# rewriting list
result = []
for (k, v), a in d.items():
    result.append([k, v, str(a).replace('.', ',')])