Data Structures: Interactive Python Lessons
Practice Python lists, dictionaries, tuples, and sets with interactive exercises. Learn when to use each structure and how to slice, iterate, and transform data like a pro.
62 lessons in this topic. Every lesson runs real Python in your browser with instant feedback.
Lists - Collections of Items 📋
Store multiple items in a list
List Creation
Create and print a list
List Indexing
Access list items by position
List Append
Add items to a list using append
List Iteration
Loop through list items
Dictionary Basics
Store key-value pairs
List Slicing
Extract portions of lists
Tuple Basics
Work with immutable sequences
Set Basics
Work with unique collections
List Remove
Remove items from lists
Dictionary Update
Add or change dictionary values
Nested Lists
Work with lists inside lists
Word counts in a 3-item list
Count each item in ['red', 'blue', 'red'] into a dict and print it.
Sort [3, 1, 2, 1]
Print [3, 1, 2, 1] sorted in ascending order.
Unique values of [3, 1, 2, 1]
Print the unique values of [3, 1, 2, 1], sorted (use a set).
Common items of two lists
Print the sorted values present in BOTH [3, 1, 2, 1] and [2, 3, 4].
Highest value's key
In the dict {'a': 3, 'b': 7}, print the key with the largest value.
Unpack a tuple (5, 9)
Unpack (5, 9) into x and y, then print their sum.
Sum a list of 4
Print the sum of all numbers in [3, 1, 2, 1].
Word counts in a 4-item list
Count each item in ['x', 'y', 'x', 'z'] into a dict and print it.
Sort [8, 4, 8]
Print [8, 4, 8] sorted in ascending order.
Unique values of [8, 4, 8]
Print the unique values of [8, 4, 8], sorted (use a set).
Common items of two lists (['x', 'y', 'x', 'z'])
Print the sorted values present in BOTH [8, 4, 8] and [4, 9, 1].
Highest value's key (['x', 'y', 'x', 'z'])
In the dict {'p': 10, 'q': 2}, print the key with the largest value.
Unpack a tuple (2, 6)
Unpack (2, 6) into x and y, then print their sum.
Sum a list of 3
Print the sum of all numbers in [8, 4, 8].
Word counts in a 3-item list (['cat', 'dog', 'cat'])
Count each item in ['cat', 'dog', 'cat'] into a dict and print it.
Sort [5, 5, 1, 2]
Print [5, 5, 1, 2] sorted in ascending order.
Unique values of [5, 5, 1, 2]
Print the unique values of [5, 5, 1, 2], sorted (use a set).
Common items of two lists (['cat', 'dog', 'cat'])
Print the sorted values present in BOTH [5, 5, 1, 2] and [5, 2, 7].
Highest value's key (['cat', 'dog', 'cat'])
In the dict {'m': 1, 'n': 9}, print the key with the largest value.
Unpack a tuple (11, 4)
Unpack (11, 4) into x and y, then print their sum.
Sum a list of 4 (['cat', 'dog', 'cat'])
Print the sum of all numbers in [5, 5, 1, 2].
Word counts in a 3-item list (['a', 'b', 'c'])
Count each item in ['a', 'b', 'c'] into a dict and print it.
Sort [9, 3, 6]
Print [9, 3, 6] sorted in ascending order.
Unique values of [9, 3, 6]
Print the unique values of [9, 3, 6], sorted (use a set).
Common items of two lists (['a', 'b', 'c'])
Print the sorted values present in BOTH [9, 3, 6] and [6, 1, 3].
Highest value's key (['a', 'b', 'c'])
In the dict {'k': 4, 'j': 8}, print the key with the largest value.
Unpack a tuple (7, 7)
Unpack (7, 7) into x and y, then print their sum.
Sum a list of 3 (['a', 'b', 'c'])
Print the sum of all numbers in [9, 3, 6].
Word counts in a 3-item list (['up', 'up', 'down'])
Count each item in ['up', 'up', 'down'] into a dict and print it.
Sort [2, 2, 2, 5]
Print [2, 2, 2, 5] sorted in ascending order.
Unique values of [2, 2, 2, 5]
Print the unique values of [2, 2, 2, 5], sorted (use a set).
Common items of two lists (['up', 'up', 'down'])
Print the sorted values present in BOTH [2, 2, 2, 5] and [5, 8, 2].
Highest value's key (['up', 'up', 'down'])
In the dict {'s': 6, 't': 6}, print the key with the largest value.
Unpack a tuple (3, 12)
Unpack (3, 12) into x and y, then print their sum.
Sum a list of 4 (['up', 'up', 'down'])
Print the sum of all numbers in [2, 2, 2, 5].
Sort [4, 2, 3, 2]
Print [4, 2, 3, 2] sorted in ascending order.
Unique values of [4, 2, 3, 2]
Print the unique values of [4, 2, 3, 2], sorted (use a set).
Common items of two lists (['red', 'blue', 'red'])
Print the sorted values present in BOTH [4, 2, 3, 2] and [3, 4, 5].
Sum a list of 4 (['red', 'blue', 'red'])
Print the sum of all numbers in [4, 2, 3, 2].
Sort [9, 5, 9]
Print [9, 5, 9] sorted in ascending order.
Unique values of [9, 5, 9]
Print the unique values of [9, 5, 9], sorted (use a set).
Common items of two lists (['x', 'y', 'x', 'z']·2)
Print the sorted values present in BOTH [9, 5, 9] and [5, 10, 2].
Sum a list of 3 (['x', 'y', 'x', 'z'])
Print the sum of all numbers in [9, 5, 9].
Sort [6, 6, 2, 3]
Print [6, 6, 2, 3] sorted in ascending order.
Unique values of [6, 6, 2, 3]
Print the unique values of [6, 6, 2, 3], sorted (use a set).
Common items of two lists (['cat', 'dog', 'cat']·2)
Print the sorted values present in BOTH [6, 6, 2, 3] and [6, 3, 8].
Sum a list of 4 (['cat', 'dog', 'cat']·2)
Print the sum of all numbers in [6, 6, 2, 3].
Sort [10, 4, 7]
Print [10, 4, 7] sorted in ascending order.
Unique values of [10, 4, 7]
Print the unique values of [10, 4, 7], sorted (use a set).
Common items of two lists (['a', 'b', 'c']·2)
Print the sorted values present in BOTH [10, 4, 7] and [7, 2, 4].