I have multiple files with data written in two column looks like:
asp 1.88
gln 3.10
arg 0.99
his 1.11
and
asp 0.99
gln 1.11
arg 0.08
his 0.01
and so on.
What I want to do is add them up and write to a new file like this:
asp 2.87
gln 4.21
arg 1.07
his 1.12
I was trying by importing Counter but it is not doing well. I also tried like this:
inp = ('c"/users/ansm/desktop/xx.txt','r').read().strip().split('\n')
inp2 = ('c"/users/ansm/desktop/xyz.txt','r').read().strip().split('\n')
c = Counter(inp)
d = Counter(inp2)
print c+d
but this code doesn’t add up the values.
Is there any other way to do it without using Counter?
I was using glob.iglob to iterate throughout the folder for files with .txt format and then want to process them to get above mentioned result. Will using Counter be the most efficient way to do it or would some other way even better?
Create the Counters using this construct:
The result
c+dwill be:EDIT for many files: