python---文件操作练习

from collections import Counter
import random
with open ('ips.txt','a+') as f:
    for i in range(120000):
        f.write('172.25.254.' + str(random.randint(1,254))+'\n')
from collections import Counter
with open('ips.txt','r') as f:
    d = {}
    for i in f:
        if i.strip() in d:
            d[i.strip()] += 1
        else:
            d[i.strip()] = 0
print(d)
c = Counter(d)
e = c.most_common(10)
print(e)

这里写图片描述

猜你喜欢

转载自blog.csdn.net/suifengOc/article/details/82110739