统计一组数据的次数

#!/usr/bin/env python
# coding=utf-8


aa = open('C:/Users/12041/Desktop/text.txt','r',encoding='utf-8')
a = []
while True:
line = aa.readline().strip()
if line:
a.append(line)
else:
break
b = list(set(a))
for i in b:
print("%s has %s"%(i,a.count(i)))

猜你喜欢

转载自www.cnblogs.com/yymhaha/p/9250499.html