DS 1501 · Lesson 14 of 24
Instructor: Corey Schafer9m
Sign in to watchRepresent structured records, lookup tables, and word/category counts cleanly in O(1) average time using Python dictionaries. What you will learn: • Creating dicts with {}, key constraints (keys must be hashable/immutable: str, int, tuple; values can be anything). • Accessing and modifying entries: d[k], safe d.get(k, default) avoiding KeyError, updating, and del / d.pop(k). • Inspecting dynamic views: d.keys(), d.values(), d.items() and membership testing (k in d). • Classic Data Science frequency-counter pattern with d.get(word, 0) + 1. University Outline Mapping: Class 14 · CO4 · Reading: 6.2 (deitel) · Activities: Lecture, Slides, Demonstration.
Note
Outline: Class 14 | CO4 | Reading: Deitel 6.2 Frequency Map Pattern: counts = {} for tag in ['ds', 'py', 'ds', 'ml']: counts[tag] = counts.get(tag, 0) + 1 # {'ds': 2, 'py': 1, 'ml': 1} Exam Trap: 'val in d' checks KEYS, not values! To search values, test 'val in d.values()'.
Same resources as in the community course — sign in to watch the lesson and track progress.
Watch the whole course.
Sign in to play every lesson, track your progress, and ask questions alongside the community.
Already signed in? Open lesson in Community