-
Notifications
You must be signed in to change notification settings - Fork 0
/
PolySort.py
69 lines (60 loc) · 2.49 KB
/
PolySort.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
print("""
@@@@@@@ @@@ @@@ @@@@@@ @@@@@@ @@@@@@@ @@@@@@@
@@@@@@@@ @@@ @@@ @@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@
@@! @@@ @@! !@@ !@@ @@! @@@ @@! @@@ @@!
!@! @!@ !@! @!! !@! !@! @!@ !@! @!@ !@!
@!@@!@! !@!@! !!@@!! @!@ !@! @!@!!@! @!!
!!@!!! @!!! !!@!!! !@! !!! !!@!@! !!!
!!: !!: !:! !!: !!! !!: :!! !!:
:!: :!: !:! :!: !:! :!: !:! :!:
:: :: :::: :: ::::: :: :: ::: ::
: : :: : : : : : : : : :
""")
# By: Nandan R
# Date: 28/03/2024
# Version: 1.0
def sort_dict_by_value(x):
return {k: v for k, v in sorted(x.items(), key=lambda item: item[1], reverse=True)}
No_of_Wordlists: int = int(input("Enter the number of wordlists: "))
Wordlists = []
print("Wordlists must be saved in the WordLists folder.")
for i in range(No_of_Wordlists):
Wordlist = input("Enter the name of wordlist: ")
if Wordlist[-4:] != ".txt":
Wordlist += ".txt"
Wordlist = "WordLists/" + Wordlist
Wordlists.append(Wordlist)
def sort_dict_by_value(x):
return {k: v for k, v in sorted(x.items(), key=lambda item: item[1], reverse=True)}
output = input("Enter the name of output file: ")
output = "Output/" + output
temptxt = "TempFiles/temp0.txt"
with open(Wordlists[0],"r",encoding="iso-8859-1") as r:
lines = r.readlines()
with open(temptxt,"w",encoding="iso-8859-1") as w:
w.writelines(lines)
for i in range(No_of_Wordlists - 1):
with open(Wordlists[i+1],"r",encoding="iso-8859-1") as r:
lines = r.readlines()
with open(temptxt,"r",encoding="iso-8859-1") as r2:
lines2 = r2.readlines()
temptxt = "TempFiles/"+"temp"+str(i+1)+".txt"
with open(temptxt,"w",encoding="iso-8859-1") as w:
freq = {}
for line in lines:
if line in freq:
freq[line] += 1
else:
freq[line] = 1
for line in lines2:
if line in freq:
freq[line] += 1
else:
freq[line] = 1
freq = sort_dict_by_value(freq)
for key in freq:
w.write(key)
with open(temptxt,"r",encoding="iso-8859-1") as r:
lines = r.readlines()
with open(output,"w",encoding="iso-8859-1") as w:
w.writelines(lines)