Why Collections Matter
Unit ID: M03-U00 Estimated active time: 18-25 minutes
One value is not always enough
So far, one name has usually referred to one number, boolean, text value, or None. Real tasks often need several related values.
Imagine three kinds of information:
- A sequence of module titles in learning order.
- One course record with labelled fields such as title, hours, and status.
- A group of unique skill tags where duplicates do not matter.
Python provides different collections because these shapes are different.
Four core collection types
| Type | Main strength | Example use |
|---|---|---|
list | Ordered, changeable sequence | Module titles in course order |
tuple | Ordered, fixed grouping | A coordinate or fixed version record |
dict | Values stored under meaningful keys | One labelled course record |
set | Unique items and fast membership questions | Unique tags or categories |
The best structure depends on the task, not personal habit.
Look at the shapes
module_titles = ["Values", "Collections", "Control flow"]
version = (1, 0)
course = {"title": "Python Foundations", "hours": 32}
skill_tags = {"python", "data", "beginner"}
Notice the delimiters:
- lists use square brackets;
- tuples usually use parentheses;
- dictionaries use braces with key-value pairs;
- sets use braces with individual values.
An empty pair of braces {} creates an empty dictionary, not an empty set. Use set() for an empty set.
Pause and choose
Choose a structure for each need:
- the first, second, and third assessment attempts;
- a record containing a learner-safe fictional course code, title, and duration;
- the unique file types used by a project;
- a fixed red-green-blue colour triple.
Reasonable choices are a list, dictionary, set, and tuple. Other choices may work, but you should explain what meaning they preserve.
Collections also have types
print(type(module_titles))
print(type(version))
print(type(course))
print(type(skill_tags))
As before, type affects the available operations.
Takeaway
Collections represent shapes of related information. Choose by order, labels, uniqueness, and whether change is expected. Next, we will begin with the most common ordered, changeable collection: the list.
