Skip to main content

Learning outcomes

By the end of this chapter, you should be able to:
  • identify list, tuple, set, and dictionary
  • explain mutable vs immutable types
  • perform basic operations on each

30-minute recording plan

  • 0-7 min: list and tuple basics
  • 7-14 min: set behavior and uniqueness
  • 14-21 min: dictionary key-value model
  • 21-26 min: mutable vs immutable comparison
  • 26-30 min: exam-type type-selection questions

Why this chapter matters

  • Most real programs store multiple values, not single values.
  • Choosing the correct data type reduces bugs and improves clarity.
  • Many exam questions ask “which type should be used and why?”

List

Ordered, mutable collection.
marks = [78, 85, 91]
marks.append(88)
print(marks)
Useful when order matters and values can change.

Tuple

Ordered, immutable collection.
point = (2, 5)
Use tuple for fixed records.

Set

Unordered collection of unique elements.
s = {1, 2, 2, 3}
print(s)  # {1, 2, 3} (order may vary)
Useful for duplicate removal and membership checks.

Dictionary

Key-value mapping.
student = {"name": "Dhruv", "marks": 89}
print(student["name"])
Useful when data is naturally labeled by keys.

Mutable vs immutable

  • mutable: list, set, dictionary
  • immutable: tuple, string, int, float, bool

Common operations

nums = [10, 20, 30]
print(nums[0])
print(len(nums))

student = {"name": "A", "age": 19}
student["age"] = 20
print(student)

Mini showcase: attendance dashboard

names = ["Aarav", "Riya", "Aarav", "Kabir"]   # list
unique_names = set(names)                      # set for unique

roll_map = (101, 102, 103)                     # tuple (fixed)
report = {                                     # dictionary
    "total_entries": len(names),
    "unique_students": len(unique_names),
    "students": sorted(unique_names)
}

print(report)
This single snippet shows when each container is useful.

Exam-focused points

  • list uses [], tuple uses (), set uses {} without key-value pairs
  • dictionary keys must be unique
  • sets remove duplicates and are unordered

Practice questions

  1. Create a list of 5 numbers and print max/min.
  2. Create a dictionary for a student with 4 fields.
  3. Convert list [1, 2, 2, 3, 3, 3] into unique values using set.