37 lines
580 B
Python
37 lines
580 B
Python
students = [
|
|
"john",
|
|
"jane",
|
|
"bob",
|
|
"alice",
|
|
"charlie",
|
|
"david",
|
|
"emily",
|
|
"frank",
|
|
"grace",
|
|
"harry",
|
|
"isabella",
|
|
"jessica",
|
|
]
|
|
|
|
with open("students.txt", "w") as f:
|
|
for student in students:
|
|
f.write(f"{student}\n")
|
|
|
|
students = []
|
|
|
|
with open("students.txt", "r") as f:
|
|
for line in f:
|
|
students.append(line.strip())
|
|
|
|
print("Unsorted: ")
|
|
print(students)
|
|
|
|
students.sort()
|
|
print("")
|
|
|
|
print("Sorted: ")
|
|
print(students)
|
|
|
|
with open("students.txt", "w") as f:
|
|
for student in students:
|
|
f.write(f"{student}\n") |