Write a complete Python program that opens a file called 'myfile', reads the entire contents of the file into a string s, determines the number of words in myfile and prints that number on a line, then prints out all words in myfile in alphabetical order, each word on a separate line.

Respuesta :

Answer:

myfile = open("myfile","r").readlines();

myfile_altered = "".join(myfile.split("\n"))

length = len(myfile_altered)

myfile_sort = " ".join(myfile).split(" ")

myfile.sort()

print(length)

print(myfile)

Explanation:

I read the file and split the text by a space, and just sorted the list using `.sort()`

Should work (didnt test it). If it doesn't, just comment on this answer and I will debug it.

ACCESS MORE