Sets and Dictionaries Python practice problems
Uniqueness, membership tests, key-value lookup, frequency counting, and grouping.
Core concepts
Problem-solving patterns
- set operators · sorting
- set · normalization
- Counter · dictionary
- nested data · average
- state update · business rule
What this topic builds
Learn the idea once, use it across the exercises, and explain why your approach works.
All 20 problems in this topic
Work from top to bottom to build the concept gradually.
- #113Calculate set union and intersection: Shared course IDsStarterPremium
Compare course IDs selected by two students.
- #114Calculate set union and intersection: Disjoint choicesStarterPremium
Handle two groups with no values in common.
- #115Count unique words: Repeated topic wordsStarterPremium
Count distinct words in a short, case-insensitive note.
- #116Count unique words: All repeatedStarterPremium
Return one when the same word appears with different capitalization.
- #117Build a word-frequency table: Analyze feedbackBeginnerPremium
Count every word in a short feedback line.
- #118Build a word-frequency table: Single vocabulary itemBeginnerPremium
Count a line containing just one repeated word.
- #119Calculate a student's average: Three assessmentsBeginnerPremium
Create a small record and report a learner's average.
- #120Calculate a student's average: Decimal resultsBeginnerPremium
Support assessment scores with decimal values.
- #121Update inventory: Deliveries and salesBeginnerPremium
Apply a sequence of deliveries and sales to current stock.
- #122Update inventory: Prevent negative stockBeginnerPremium
Clamp stock at zero if an outgoing request exceeds availability.
- #123Group anagrams: Several word familiesBeginnerPremium
Group words that contain the same letters.
- #124Group anagrams: No matchesIntermediatePremium
Produce one single-word group for each unrelated word.
- #125Invert a dictionary: Code lookupIntermediatePremium
Reverse a name-to-code mapping so codes become searchable keys.
- #126Invert a dictionary: Numeric-looking valuesIntermediatePremium
Invert text pairs whose values happen to contain digits.
- #127Find the top k frequent values: Top two product codesIntermediatePremium
Find the two most frequent product codes.
- #128Find the top k frequent values: Frequency tieIntermediatePremium
Break equal-frequency ties by choosing smaller values first.
- #129Merge numeric dictionaries: Combine branch salesIntermediatePremium
Add sales totals from two branches by product key.
- #130Merge numeric dictionaries: No shared keysAdvancedPremium
Merge mappings whose keys do not overlap.
- #131Build an adjacency list: Small networkAdvancedPremium
Convert a small undirected network into neighbor lists.
- #132Build an adjacency list: Include an isolated vertexAdvancedPremium
Show an empty adjacency list for a vertex with no edges.