用python写了一个统计用户资料sql文件中的所用的邮箱的数量,总数600W+,算上屏幕输出共耗时5min+:
from __future__ import division
from operator import itemgetter
sql = open("www.csdn.net.sql","r+")
d = {}
iCount = 0
for eachLine in sql :
line_list = eachLine.strip().split(" # ")
e_address = line_list[2]
if "@" in e_address :
e_domain = e_address.split("@")[1]
else :
e_domain = e_address
#print e_domain
if e_domain not in d :
d[e_domain] = 1
iCount += 1
else :
d[e_domain] += 1
iCount += 1
print "*" * 80
print "Sum:",str(iCount)
print "*" * 80
l = sorted(d.iteritems(), key=itemgetter(1),reverse=True) # 据说这种对字典值的排序方法效率最高
for eachItem in l :
print eachItem,str(((int(eachItem[1]))/iCount) * 100.0)+"%"
另外,发现了一个不错的网站,叫OSChina(http://www.oschina.net/),是一个跟开源有关的网站,有很多优秀的成熟的源代码,读读肯定会自己的能力的提高有好处的。
另:Python排序参考:
http://www.cnblogs.com/itech/archive/2011/12/27/2303740.html
http://zuroc.42qu.com/10037539
统计结果截图: