+ 2
l am able to open and read a file but my problem is to sort the content in alphabetical order can someone help
2 Réponses
+ 6
Something like this:
with open('filename.txt', 'r') as f:
for line in sorted(f):
print(line, end='')
+ 1
You could open each line of the file into a list, and sort that list into alphabetical order:
file = open ("filename. txt","r")
list = file.readlines ()
list.sort ()
Hope this alternative way helps!