ip存储与读取文件统计ip频率 (京东二面题)• 生成一个大文件ips.txt,要求120000行,每行随即为172.25.254.0/24段的ip;• 读取ips.txt文件统计这个文件中ip出现频率前10的ip# ip生成及存入文件def ip_create(): import random import json global ipshow ipshow = 0 with open("ips.txt", "w+") as fp...
def ip_create():
import random
import json
global ipshow
ipshow = 0
with open("ips.txt", "w+") as fp:
for i in range(1000):
#生成ip地址
str1 = random.randint(1, 256)
ip = f'172.25.254.{str1}'
# ips = json.dumps(ip)
fp.write(ip + '\n')
# print(ip)
with open("ips.txt", "r+") as fp:
ipshow = fp.read()
# ip_create()
def sorted_ip(filename, count=10):
#初始化
ips_dict = dict()
with open(filename) as f:
for ip in f:
if ip in ips_dict:
ips_dict[ip] += 1
else:
ips_dict[ip] = 1
# sorted(
ip存储与读取文件统计ip频率 (京东二面题)• 生成一个大文件ips.txt,要求120000行,每行随即为172.25.254.0/24段的ip;• 读取ips.txt文件统计这个文件中ip出现频率前10的ip# ip生成及存入文件def ip_create(): import random import json global ipshow ipshow = 0 with open("ips.txt", "w+") as fp...