Homework

7.5.3. Homework#

  • Use this assignment to practice the chapter’s concepts and coding skills in runnable Python code.

  • Sign in from the account menu before you start working on the assignment.

  • Write and run your code directly in the coding cells.

  • Multiple submissions are allowed. The highest score is kept.

1. Key Lookup

A support dashboard can use a dictionary to look up a customer plan quickly from a username key.

2. Missing Keys

Using scores["missing"] is always safer than .get() when a key may not exist.

3. Nested Dictionaries

A roster keyed by course code can store another dictionary for section metadata such as instructor and seat count.

4. Sets

A set is the right collection when a report must preserve duplicate names exactly as they appeared.

5. Hashability

A list can always be placed inside a set because all Python objects are hashable.

### 6. Look up with a fallback
# Use `.get()` to print the requested plan.
# Print exactly this line:
# Plan for chen: trial
plans = {"ana": "pro", "bob": "basic"}
user = "chen"

### Your code starts here.



### Your code ends here.
### 7. Build a frequency dictionary
# Count departments.
# Print exactly this line:
# Counts: {'sales': 2, 'ops': 3, 'data': 1}
departments = ["sales", "ops", "sales", "data", "ops", "ops"]

### Your code starts here.



### Your code ends here.
### 8. Group values by key
# Group names by role.
# Print exactly this line:
# Groups: {'analyst': ['Ana', 'Chen'], 'manager': ['Bob']}
people = [("Ana", "analyst"), ("Bob", "manager"), ("Chen", "analyst")]

### Your code starts here.



### Your code ends here.
### 9. Find unique categories
# Use a set and sorted list.
# Print exactly this line:
# Categories: ['api', 'data', 'web']
categories = ["data", "web", "data", "api", "web"]

### Your code starts here.



### Your code ends here.
### 10. Use set algebra
# Create active paid users with set intersection.
# Print exactly this line:
# Active paid users: ['ana', 'chen']
active = {"ana", "bob", "chen"}
paid = {"ana", "chen", "dee"}

### Your code starts here.



### Your code ends here.