How to sort a text file.txt in python? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

How to sort a text file.txt in python?

a = f open("file.txt", r) a.split Sort?

29th Nov 2019, 12:43 AM
Firman Maulana
Firman Maulana - avatar
2 Réponses
+ 1
Ok, thank I can try it
29th Nov 2019, 1:04 AM
Firman Maulana
Firman Maulana - avatar
0
When you handle a file you need to open, handle and close it. You can use: file = open("file.txt", "r") text = file.read() file.close() After that you can handle variable text like any string: print(sorted(text.split()))
29th Nov 2019, 1:02 AM
Seb TheS
Seb TheS - avatar