Ask 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 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. 19 September, 13:12
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers