-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort.py
31 lines (23 loc) · 1.04 KB
/
sort.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
#THIS CODE SORT THE 2 FILES CALLED "emu.txt" AND "no_emu.txt"
# Read the file and create a list of tuples
with open('emu.txt', 'r') as file:
lines = [line.strip().split(' ') for line in file]
# Convert the first column to integers for proper sorting
lines = [(int(line[0]), line[1], line[2]) for line in lines]
# Sort the list in descending order
lines.sort(reverse=True)
# Write the sorted list back to the existing file
with open('emu.txt', 'w') as file:
for line in lines:
file.write(f"{line[0]} {line[1]} {line[2]}\n")
# Read the file and create a list of tuples
with open('no_emu.txt', 'r') as file:
lines = [line.strip().split(' ') for line in file]
# Convert the first column to integers for proper sorting
lines = [(int(line[0]), line[1], line[2]) for line in lines]
# Sort the list in descending order
lines.sort(reverse=True)
# Write the sorted list back to the existing file
with open('no_emu.txt', 'w') as file:
for line in lines:
file.write(f"{line[0]} {line[1]} {line[2]}\n")