facebook - Python - Addition and merging with an array -


i'm using facebook api collect data on mentions. i'm collecting month , amount of times term (eg: banana) has been mentioned in post. have data coming in looks this:

12, 0 12, 0 11, 1 11, 0 11, 1 10, 0 10, 0 10, 0 

each row represents 1 post. want merge months (first column) , number of times term has been mentioned (second column) looks this:

12, 0 11, 2 10, 0 

i tried putting data in array so:

[12, 0] [12, 0] [11, 1] [11, 0] [11, 1] [10, 0] [10, 0] [10, 0] 

but unable figure out way of merging , adding columns. there anyway of doing this?

assuming data list of tuples or lists, can use defaultdict , iterate on list, e.g.:

>>> collections import defaultdict >>> d = defaultdict(int) >>> m, c in data: ...     d[m] += c >>> list(d.items()) [(10, 0), (11, 2), (12, 0)] 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -