Dictionaries are very useful data structures, more versatile and powerful than lists.
1. Remix the trinket on the right to make your own copy. Call it "Dictionaries - Introduction".
2. Read the tutorial and code exercises 1, 2, 3 (in the tutorial), into the window on the right.
Hint:
- you can use the built-in Python split(), sorted() and keys() functions to help you simplify your code (look up the Python documentation).
3. When done with the tutorial exercises, save your work and submit the link through Veracross.
1. Make sure you fully understand the example given in the section "Dictionaries as a set of counters" (you may want to actually program it and see it working).
That example will help you program the following project.
2. Remix the program in the window on the right, and call it "Dictionaries - project 1".
3. In the window on the right, in the file zen.py, there is a string variable containing the "Zen of Python".
Write a program, using dictionaries, to count and print how many times each word shows up in this text.
Hints:
- you should clean up the text, getting rid of any non-word and punctuation characters, before you start counting words. A "skeleton" clean() function is provided for you to create in the zen.py tab.
- you can use the built-in Python split() function to help you simplify your code (look up the Python documentation).
The output of your program should look similar to the following (partial output):
4. When done, save your work and submit the link through Veracross.
Create a new program by duplicating the program above and modifying it for this exercise.
1. Duplicate the program you finished in project 1, and call it "Dictionaries - project 2".
2. Modify your duplicated program to print the count of the alphabetically-sorted words.
Hint:
- you can use the built-in Python sorted() and keys() functions to help you simplify your code (look up the Python documentation).
The output of your program should look similar to the following (partial output):
3. Enhance your program to ask the user if they want the sorted output or not, and print the word count accordingly (sorted or unsorted based on the user's response).
4. Finally, add the capability to print the reverse lookup of the text, listing the word count in ascending order, first, followed by all the words with that word count.
The output of your program should look similar to the following (partial output):
5. When done, save your work and submit the link through Veracross.