Summary
In this lecture I walk through the essential features of Python dictionaries and sets, showing how they can be leveraged to clean, transform, and summarize a storm‑damage dataset. I begin by clarifying course logistics before diving into dictionary fundamentals: keys must be unique (duplicates are overwritten), values may be any type—including lists and nested dictionaries—and len() returns the number of keys. Using .items() I demonstrate unpacking key/value pairs for iteration, which lets me build formatted summary strings and compute aggregates such as the maximum wind speed via max() with a lambda that accesses a specific field. I then introduce more advanced operations: merging dictionaries with the pipe (|) operator for a new combined dict, updating in place with .update(), and using dictionary comprehensions to filter or transform data succinctly.
Applying these tools to the storm dataset, I filter for category 3+ storms and convert damage figures from billions to millions with a single dictionary comprehension (damage × 1,000). I also show the numeric‑underscore trick for readable large literals. Next, I shift to sets to extract unique city names from each storm’s area list and to compile a master set of all affected cities. I explain set creation (literal {} for non‑empty, set() for empty), the unordered nature of sets, and the use of set.add for single elements and set.update for merging iterables.
By the end of the session you should be able to:
- Construct, query, and modify dictionaries effectively.
- Use comprehensions for filtering and unit conversion.
- Merge and update dictionaries cleanly.
- Apply sets to deduplicate and aggregate categorical data.
The next step is to practice these patterns on your own data: create a dictionary of storm records, filter by category, convert damage units, and generate a unique city list using sets. This will reinforce the techniques and prepare you for more complex data‑processing tasks in upcoming labs and projects.