Actual Programming w/ Dictionaries
1
CS 110
Reminders and Announcements
Announcements
This Week
Next Week
Finals Week
Dictionaries (Cheat Sheet)
3
Create a dictionary | my_dict = {} |
Get element from a dictionary | my_dict.get(key) |
Add/replace items in dictionary | my_dict[key] = value |
Remove items from dictionary | del my_dict[key] |
Iterate through a dictionary | for key in my_dict:� print(key, my_dict[key]) |
Check if key exists in dictionary | if my_dict.get(key) != None if key in my_dict… |
Dictionaries: When are they useful?
4
Dictionary counting algorithms
Dictionaries also help us to count and group things. Examples:
5
Tallying and Counting
How many times does each letter in the word supercalifragilisticexpialidocious appear?
The algorithm:
01_count_letters.py & Python Tutor
Activity: 02_count_words.py
Now, let's apply the same idea but counting unique WORDS in the novel Moby Dick!
7
Activity: 03_restaurant_violations.py
Write a program that reads the contents of the Food_Establishment_Violations.csv for the City of Evanston and counts the number of violations that have occurred for each restaurant code. Then, print out the restaurant's name and the number of violations for that restaurant.
Note that the part that creates a lookup dictionary between restaurant "codes" (license number) and business name is already done for you!
8
Web APIs
9
Your Computer
Server
APIs
Examples of Web APIs
Some examples of companies and organizations that have REST APIs include
10
Access and Authentication
11
Speaking of existing functions…
12