✦ Python Foundations Collections module

Concept 14 · Choosing the Right Collection

Choose for the job.
Match the collection to the data.

Choose based on whether order, changeability, uniqueness, or access by a meaningful key matters most.

01 Learn02 Try03 Predict

Each collection solves a different data problem.

Choose based on whether order, changeability, uniqueness, or access by a meaningful key matters most.

tasks = ["Design", "Code"]
coordinates = (45.26, 19.83)
print(tasks[0])
print(coordinates[1])

Lists keep ordered values you can change, while tuples keep ordered values whose items are not replaced.

Try changing one value, then explain which part of the collection changed and why.

↳

Keep this in mind: Read the collection operation before predicting the result.

Try it
tasks = ["Design", "Code", "Test"]
coordinates = (45.26, 19.83)
tags = {"python", "django", "python"}
student = {"name": "Ana", "course": "Python"}

print(tasks[0])
print(coordinates[1])
print(len(tags))
print(student["name"])

Run the example, then change one value and observe the result.

Use a list for ordered, changeable items
tasks = ["Design", "Code"]
tasks.append("Test")

A list is useful when order matters and you need to add, remove, or replace items.

Use a tuple for fixed ordered values
coordinates = (45.26, 19.83)

A tuple keeps related values in order when its items should not be replaced.

Use a set for unique values
tags = {"python", "django", "python"}

A set removes duplicates and does not provide positional indexing.

Use a dictionary for named data
student = {"name": "Ana", "city": "Novi Sad"}

A dictionary connects meaningful keys to values for direct lookup.

Python Playground

Loading Python runtime…

Edit the example and run it in your browser.

choosing_the_right_collection.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

Read each operation before choosing an answer.

visitors = ["Ana", "Marko", "Ana"]
unique_visitors = set(visitors)

print(len(visitors))
print(len(unique_visitors))
Choose the output
Sloby, the Python AI Tutor mascot

Your learning mentor

Ask Sloby about this concept

Describe what feels unclear and Sloby will guide your reasoning.

Hi! I'm Sloby. Let's explore this Python concept together.

Which collection would you choose for: A a growing task list, B fixed coordinates, C unique article tags, and D user data accessed by name, email, and city? Explain why.

collections = ["list", "tuple", "set", "dict"]
print("Choose the right collection for each situation.")
Python AI Tutor · Learn by understanding, not just by running code.