TensorLearn
Back to Course
Python Essentials: The Engineering Approach
Module 7 of 20

7. Dictionaries & Sets

Hash Maps

A Dictionary is a Hash Map. It allows O(1) lookups. When you say d["key"]:

  1. Python calculates hash("key").
  2. Uses the hash to jump directly to the memory address.

Dictionary Views

In modern Python, methods like .keys() and .items() return live views, not lists. This saves memory.

Sets

Sets are Dictionaries without values. They enforce uniqueness.

python
# Set Logic a = {1, 2, 3} b = {3, 4, 5} print(a & b) # Intersection: {3} print(a | b) # Union: {1, 2, 3, 4, 5} print(a - b) # Difference: {1, 2}

Mark as Completed

TensorLearn - AI Engineering for Professionals