1.数据分割
filepath=
r"这里填要处理的文件路径"
passwordpath=
r"这里自定义截取密码后的路径\截取密码.txt"
readfile=open(filepath,
"r",errors=
"ignore")
passwordfile=open(passwordpath,
"w")
while True:
line = readfile.readline()
if not line:
break
csdnList = line.split(
" # ")
passwordfile.write(csdnList[
1]+
"\n")
readfile.close()
passwordfile.close()
2.数据排序
对截取的密码数据进行排序,以便后边查重
filepath=
r"这里是截取好密码的路径\截取密码.txt"
passwordpath=
r"这里自定义对密码排序后要保存的路径\密码排序1.txt"
readfile=open(filepath,
"r",errors=
"ignore")
passwordfile=open(passwordpath,
"w")
csdnList = readfile.readlines()
csdnList.sort()
for pwd
in csdnList:
passwordfile.write(pwd)
readfile.close()
passwordfile.close()
3.分析密码出现次数
filepath=
r"这里是对密码排序后的路径\密码排序1.txt"
passwordpath=
r"这里自定义对密码判断出现次数的路径\判断出现次数.txt"
readfile=open(filepath,
"r",errors=
"ignore")
passwordfile=open(passwordpath,
"w")
csdnList = readfile.readlines()
pwdLength = len(csdnList)
i =
0
while i < pwdLength:
times =
1
while i+
1 <= pwdLength-
1 and csdnList[i] == csdnList[i+
1]:
times +=
1
i +=
1
passwordfile.write(str(times)+
" # "+csdnList[i])
i +=
1
readfile.close()
passwordfile.close()
4.根据次数进行排序
filepath=
r"这里是对密码判断出现次数的路径\判断出现次数.txt"
passwordpath=
r"这里自定义对密码判断出现次数排序的路径\出现次数排序.txt"
readfile=open(filepath,
"r",errors=
"ignore")
passwordfile=open(passwordpath,
"w")
newList = []
csdnList = readfile.readlines()
for line
in csdnList:
lineList = line.split(
" # ")
newLineList = [eval(lineList[
0]),lineList[
1]]
newList.append(newLineList)
newList.sort(key=
lambda x:x[
0])
newList.reverse()
for pwd
in newList:
passwordfile.write(str(pwd[
0]) +
"," + pwd[
1])
readfile.close()
passwordfile.close()