Tanvir
commited on
Commit
โข
8ce5060
1
Parent(s):
c55f0f5
add sort-lines.py and remove-duplicates.py
Browse files- remove-duplicates.py +17 -0
- sort-lines.py +16 -0
remove-duplicates.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
+
if len(sys.argv) > 1:
|
4 |
+
filename = sys.argv[1]
|
5 |
+
else:
|
6 |
+
filename = input("Enter the name of the file to be processed: ")
|
7 |
+
|
8 |
+
with open(filename, 'r') as file:
|
9 |
+
lines = file.readlines()
|
10 |
+
|
11 |
+
unique_lines = list(set(lines))
|
12 |
+
num_duplicates = len(lines) - len(unique_lines)
|
13 |
+
|
14 |
+
with open(filename, 'w') as file:
|
15 |
+
file.writelines(unique_lines)
|
16 |
+
|
17 |
+
print(f"Removed {num_duplicates} duplicates.")
|
sort-lines.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
+
if len(sys.argv) > 1:
|
4 |
+
filename = sys.argv[1]
|
5 |
+
else:
|
6 |
+
filename = input("Enter the name of the file to be sorted: ")
|
7 |
+
|
8 |
+
with open(filename, 'r') as file:
|
9 |
+
lines = file.readlines()
|
10 |
+
|
11 |
+
lines.sort()
|
12 |
+
|
13 |
+
with open(filename, 'w') as file:
|
14 |
+
file.writelines(lines)
|
15 |
+
|
16 |
+
print("File sorted successfully!")
|