Courses‎ > ‎Intro to CS - Full Year‎ > ‎Spring‎ > ‎Dyrland-Weaver‎ > ‎Work‎ > ‎

Work 30: 4/30

posted Apr 30, 2019, 11:34 AM by JonAlf Dyrland-Weaver   [ updated Apr 30, 2019, 12:37 PM ]
The following line of python code will read in a file and store it as a string in the variable text.
  • text = open("file").read()
  • Obviously, replace file with the name of the file you want to read.
Perform the following tasks on this text file: https://github.com/mks22-dw/python/blob/master/text/wonderland.txt
  1. Create a dictionary that contains the frequencies of each character that appears in the file.
    • One hopes you have a function that does this already...
  2. Print out the character that appears the most often.
    • Remember the sorted() function, which can help (see the merge sort lab for a refresher).
    • In class yesterday I presented d.values() and d.keys() as functions that return lists. I was wrong. 
      • In order to make the lists, use the list() function like so
        • list(d.values())
        • list(d.keys())
CHALLENGE
    • Print out the 5 most frequently appearing characters, in order.
Submit this as char_count
Comments