Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

PY
Python
0/14 completed
Beginner
Hello PythonVariables and typesWorking with stringsConditions and loopsFunctions
Intermediate
Lists, tuples, dicts and setsFiles and exceptionsModules and the standard library
Advanced
Classes and OOPIterators and generatorsDecorators and context managers
Pro
Async PythonTesting and type hintsVirtual environments, packages and real projects
Tracks / Python / Intermediate

Lists, tuples, dicts and sets

Real programs work with collections of data: a list of orders, a dictionary of settings, a set of tags. Python's four built-in collections cover almost everything.

Type Example Ordered Changeable Duplicates
list [1, 2, 2] ✅ ✅ ✅
tuple (1, 2, 2) ✅ ❌ ✅
dict {"a": 1} ✅ (insertion order) ✅ Keys unique
set {1, 2} ❌ ✅ ❌

Lists

Python · editable

Lists are mutable: you can change them in place.

Python · editable

Copies vs references

Assigning a list to another variable does not copy it. Both names point to the same list:

Python · editable

List comprehensions

A comprehension builds a new list from another sequence in one readable line:

Python · editable

It's the same as a for loop that appends, but shorter and usually faster.

Tuples

A tuple is like a list that can't change. Use it for fixed groups of values, like coordinates or a database row:

Python · editable

Because they can't change, tuples can be used as dictionary keys and set members, and they signal "this data is fixed".

Dictionaries

A dict maps keys to values, like a real dictionary maps words to definitions. Looking up a key is instant, however big the dict:

Python · editable

Looping over a dict

Python · editable

Counting and grouping

Two patterns you'll write constantly:

Python · editable

Dict comprehensions

Python · editable

Sets

A set holds unique values, with very fast membership checks and set maths:

Python · editable

Nested data

Real data (like JSON from an API) is usually lists of dicts:

Python · editable

Practice

  1. Given nums = [4, 8, 15, 16, 23, 42], build a list of the numbers greater than 10, doubled, using a comprehension.
  2. Count how many times each letter appears in "mississippi".
  3. Two lists of students took two exams. Find who took both, and who took only the first.
  4. From the products list above, build a dict mapping each product name to its price.
Python · editable
✎ Check your understanding

1.After a = [1, 2]; b = a; b.append(3), what is a?

2.What does user.get("email", "none") return when there's no email key?

3.Which collection is best for checking quickly whether a username is already taken?

← Functions