Python sum of the array elements
Question: I have file with following lines:

    
    
    date:ip num#1 num#2   
    
    2013.09:142.134.35.17 10 12
    2013.09:142.134.35.17 4 4
    2013.09:63.151.172.31 52 13
    2013.09:63.151.172.31 10 10
    2013.09:63.151.172.31 16 32
    2013.10:62.151.172.31 16 32
    

How do I sum up the last two elements with the same IP to get such a
conclusion?

    
    
    2013.09:142.134.35.17 14 16
    2013.09:63.151.172.31 78 55
    2013.10:62.151.172.31 16 32
    


Answer: Try this:

    
    
    from collections import Counter
    with open('full_megalog.txt') as f:
        data = [d.split() for d in f]
    
    sum1, sum2 = Counter(), Counter()
    
    for d in data:
        sum1[d[0]] += int(d[1])
        sum2[d[0]] += int(d[2])
    
    for date_ip in sum1.keys():
        print date_ip, sum1[date_ip], sum2[date_ip]
    

