pyPython Practice LabFrom first print to final round
TOPIC 06 OF 18

Sets and Dictionaries Python practice problems

Choose sets for membership and dictionaries for relationships, grouping, and frequency tables.

20 exercises8+ conceptsBeginner → interview context
Start this topic
WHAT YOU WILL PRACTISE

Core concepts

Calculate set union and intersectionCount unique wordsBuild a word-frequency tableCalculate a student's averageUpdate inventoryGroup anagramsInvert a dictionaryFind the top k frequent values
REUSABLE THINKING

Problem-solving patterns

  • Use a set for membership; use a dictionary for key-to-value state
INTERVIEW SIGNALS

Reported company tags

AmazonGoogleMicrosoftMeta
Community-reported tags are guidance, not guarantees.
ORDERED PRACTICE

All 20 problems in this topic

Work from top to bottom to build the concept gradually.

  1. #101
    Calculate set union and intersection: Shared course IDs

    Compare course IDs selected by two students.

    IntermediatePremium
  2. #102
    Calculate set union and intersection: Disjoint choices

    Handle two groups with no values in common.

    IntermediatePremium
  3. #103
    Count unique words: Repeated topic words

    Count distinct words in a short, case-insensitive note.

    IntermediatePremium
  4. #104
    Count unique words: All repeated

    Return one when the same word appears with different capitalization.

    IntermediatePremium
  5. #105
    Build a word-frequency table: Analyze feedback

    Count every word in a short feedback line.

    IntermediatePremium
  6. #106
    Build a word-frequency table: Single vocabulary item

    Count a line containing just one repeated word.

    IntermediatePremium
  7. #107
    Calculate a student's average: Three assessments

    Create a small record and report a learner's average.

    IntermediatePremium
  8. #108
    Calculate a student's average: Decimal results

    Support assessment scores with decimal values.

    IntermediatePremium
  9. #109
    Update inventory: Deliveries and sales

    Apply a sequence of deliveries and sales to current stock.

    IntermediatePremium
  10. #110
    Update inventory: Prevent negative stock

    Clamp stock at zero if an outgoing request exceeds availability.

    IntermediatePremium
  11. #111
    Group anagrams: Several word families

    Group words that contain the same letters.

    IntermediatePremium
  12. #112
    Group anagrams: No matches

    Produce one single-word group for each unrelated word.

    IntermediatePremium
  13. #113
    Invert a dictionary: Code lookup

    Reverse a name-to-code mapping so codes become searchable keys.

    IntermediatePremium
  14. #114
    Invert a dictionary: Numeric-looking values

    Invert text pairs whose values happen to contain digits.

    IntermediatePremium
  15. #115
    Find the top k frequent values: Top two product codes

    Find the two most frequent product codes.

    IntermediatePremium
  16. #116
    Find the top k frequent values: Frequency tie

    Break equal-frequency ties by choosing smaller values first.

    IntermediatePremium
  17. #117
    Merge numeric dictionaries: Combine branch sales

    Add sales totals from two branches by product key.

    IntermediatePremium
  18. #118
    Merge numeric dictionaries: No shared keys

    Merge mappings whose keys do not overlap.

    IntermediatePremium
  19. #119
    Build an adjacency list: Small network

    Convert a small undirected network into neighbor lists.

    IntermediatePremium
  20. #120
    Build an adjacency list: Include an isolated vertex

    Show an empty adjacency list for a vertex with no edges.

    IntermediatePremium