假设号码存在 number.txt 文件中,内容大致如下:
13********1
13********2
13********3
13********1
13********1
python打开number.txt,建字典d,进行去重,并统计号码出现的次数:
def delduplicate(filename=None):
if filename==None:
return 0;
print "filename could not be blank"
d={}
f=open(filename,'r')
for line in open(filename):
line=f.readline().strip('\n')
if line not in d:
d[line]=1;
else:
d[line]+=1
return d
if __name__=='__main__':
filename='number.txt'
result=delduplicate(filename)
print result
Next:
试一下大量数据【赌五毛很慢