Ask Question
11 May, 23:26

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.

+5
Answers (1)
  1. 12 May, 00:52
    0
    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.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a complete Python program that opens a file called 'myfile', reads the entire contents of the file into a string s, determines the ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers