一、文件独特行数(没有重复过的那些行)
统计附件文件中与其他任何其他行都不同的行的数量,即独特行的数量。
输入输出格式:这是仅给出输出格式样例,不是结果。
输出示例
共99独特行
代码1:
以每一行内容为key,统计个数
ls = open("latex.log").readlines()
d = {}
cnt = 0
for line in ls:
d[line] = d.get(line,0) + 1
for k in d.keys():
if d[k] == 1:
cnt += 1
print("共{}独特行".format(cnt))
代码2:
参考网上的 “所有行数-重复行数=独特行数”
ls = open("latex.log").readlines()
s = set(ls)
for i in s:
ls.remove(i)
t = set(ls)
print("共{}独特行".format(len(s)-len(t)))
二、关键行数(相同行数只统计一次)
描述
关键行指一个文件中包含的不重复行。关键行数指一个文件中包含的不重复行的数量。
统计附件文件中与关键行的数量。
ls = open("latex.log").readlines()
s = set(ls)
print("共{}关键行".format(len(s)))