BiTree
  • Search For Lessons
  • Curriculum
  • Pricing
  • For Educators
  • Become a Tutor
  • About
  • Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
BiTree

Live coding lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Search For Lessons
  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Become a Tutor
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 BiTree. All rights reserved.
Curriculum/Web Development/Python Data Structures
40 minBeginner

Python Data Structures

After this lesson, you will be able to: Use lists, tuples, dictionaries, and sets to organize and manipulate collections of data.

Real programs almost always work with collections, a list of users, a record of stats, a set of unique tags. This lesson covers Python's four core data structures, when to use each one, and the most common operations on them.

Prerequisites:Python Logic and Decision Making

Lists, ordered, changeable collections

Lists hold any number of items in order. Use square brackets and access items by index (starting at 0).

python
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # apple
print(len(fruits)) # 3
fruits.append("mango") # add to end
fruits[1] = "blueberry" # change item
fruits.remove("cherry") # remove by value
for fruit in fruits:
print(fruit)

Dictionaries, labeled key/value pairs

Dictionaries pair keys with values. Use them when you want to look something up by name, not position.

python
student = {
"name": "Alex",
"age": 17,
"grades": [88, 92, 79]
}
print(student["name"]) # Alex
student["age"] = 18 # update
student["school"] = "BiTree HS" # add new key
for key, value in student.items():
print(key, "=", value)

Diagram coming soon!

Two columns labeled "Key" and "Value" in a dictionary diagram, name → Alex, age → 18, grades → [88, 92, 79]

Tuples and sets

Tuples are like lists but unchangeable, once created, you can't modify them. They use parentheses: point = (10, 20). Sets are unordered collections with no duplicates: tags = {"python", "web", "python"} becomes {"python", "web"}. Use sets when you only care about uniqueness or membership tests.

ℹ️ Tip, picking the right structure

List = ordered things you'll change. Tuple = fixed pair or record. Dictionary = look up by name. Set = unique items, fast "is X in here?" checks.

Try it: build a contacts dictionary

Build a tiny phonebook in the editor. Add three contacts, then look one up. The lookup name "Sam" is pre-loaded as input. Pass once your code prints the right number and uses a dictionary plus the `in` keyword for the lookup.

Loading exercise…
Quick Check

Which data structure is best for storing a unique list of tags?

Pick the one that automatically removes duplicates.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←Python Logic and Decision Making
Back to Web Development
Python Functions and Automation→