DS 1501 · Lesson 15 of 24
Instructor: Corey Schafer18m
Sign in to watchScale dictionaries from single mappings to nested JSON-like student/dataset records, dictionary comprehensions, and sorting by keys or values. What you will learn: • Merging and updating dictionaries: d.update(other), setdefault(), and union operator d1 | d2. • Nested structures: lists of dicts (tabular rows) and dicts of lists/dicts (grouped records). • Dictionary comprehensions: {k: v*2 for k, v in prices.items() if v > 10} and inverting maps. • Sorting dictionary entries by value using sorted(d.items(), key=lambda kv: kv[1], reverse=True). University Outline Mapping: Class 15 · CO4 · Reading: 6.2 (deitel) · Activities: Lecture, Slides, Demonstration.
Note
Outline: Class 15 | CO4 | Reading: Deitel 6.2 Nested Dictionary Traversal & Sorting: grades = {'Asha': [88, 92], 'Rafiq': [79, 85]} avg = {name: sum(xs)/len(xs) for name, xs in grades.items()} ranked = sorted(avg.items(), key=lambda p: p[1], reverse=True) Practice: Group a list of (course, score) tuples into a dict mapping each course to its score list.
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