使用
Counter(),并使用
strip()删除
n:
from collections import Counterwith open('x.txt') as f1,open('y.txt','w') as f2: c=Counter(x.strip() for x in f1) for x in c: print x,c[x] #do f2.write() here if you want to write them to f2输出:
A 1C 3EH 1IRQ 1V 2H 1IRG 1



