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.

intermediate

Lists - Collections of Items 📋

Store multiple items in a list

intermediate

List Creation

Create and print a list

intermediate

List Indexing

Access list items by position

intermediate

List Append

Add items to a list using append

intermediate

List Iteration

Loop through list items

intermediate

Dictionary Basics

Store key-value pairs

intermediate

List Slicing

Extract portions of lists

intermediate

Tuple Basics

Work with immutable sequences

intermediate

Set Basics

Work with unique collections

intermediate

List Remove

Remove items from lists

intermediate

Dictionary Update

Add or change dictionary values

intermediate

Nested Lists

Work with lists inside lists

intermediate

Word counts in a 3-item list

Count each item in ['red', 'blue', 'red'] into a dict and print it.

intermediate

Sort [3, 1, 2, 1]

Print [3, 1, 2, 1] sorted in ascending order.

intermediate

Unique values of [3, 1, 2, 1]

Print the unique values of [3, 1, 2, 1], sorted (use a set).

intermediate

Common items of two lists

Print the sorted values present in BOTH [3, 1, 2, 1] and [2, 3, 4].

intermediate

Highest value's key

In the dict {'a': 3, 'b': 7}, print the key with the largest value.

intermediate

Unpack a tuple (5, 9)

Unpack (5, 9) into x and y, then print their sum.

intermediate

Sum a list of 4

Print the sum of all numbers in [3, 1, 2, 1].

intermediate

Word counts in a 4-item list

Count each item in ['x', 'y', 'x', 'z'] into a dict and print it.

intermediate

Sort [8, 4, 8]

Print [8, 4, 8] sorted in ascending order.

intermediate

Unique values of [8, 4, 8]

Print the unique values of [8, 4, 8], sorted (use a set).

intermediate

Common items of two lists (['x', 'y', 'x', 'z'])

Print the sorted values present in BOTH [8, 4, 8] and [4, 9, 1].

intermediate

Highest value's key (['x', 'y', 'x', 'z'])

In the dict {'p': 10, 'q': 2}, print the key with the largest value.

intermediate

Unpack a tuple (2, 6)

Unpack (2, 6) into x and y, then print their sum.

intermediate

Sum a list of 3

Print the sum of all numbers in [8, 4, 8].

intermediate

Word counts in a 3-item list (['cat', 'dog', 'cat'])

Count each item in ['cat', 'dog', 'cat'] into a dict and print it.

intermediate

Sort [5, 5, 1, 2]

Print [5, 5, 1, 2] sorted in ascending order.

intermediate

Unique values of [5, 5, 1, 2]

Print the unique values of [5, 5, 1, 2], sorted (use a set).

intermediate

Common items of two lists (['cat', 'dog', 'cat'])

Print the sorted values present in BOTH [5, 5, 1, 2] and [5, 2, 7].

intermediate

Highest value's key (['cat', 'dog', 'cat'])

In the dict {'m': 1, 'n': 9}, print the key with the largest value.

intermediate

Unpack a tuple (11, 4)

Unpack (11, 4) into x and y, then print their sum.

intermediate

Sum a list of 4 (['cat', 'dog', 'cat'])

Print the sum of all numbers in [5, 5, 1, 2].

intermediate

Word counts in a 3-item list (['a', 'b', 'c'])

Count each item in ['a', 'b', 'c'] into a dict and print it.

intermediate

Sort [9, 3, 6]

Print [9, 3, 6] sorted in ascending order.

intermediate

Unique values of [9, 3, 6]

Print the unique values of [9, 3, 6], sorted (use a set).

intermediate

Common items of two lists (['a', 'b', 'c'])

Print the sorted values present in BOTH [9, 3, 6] and [6, 1, 3].

intermediate

Highest value's key (['a', 'b', 'c'])

In the dict {'k': 4, 'j': 8}, print the key with the largest value.

intermediate

Unpack a tuple (7, 7)

Unpack (7, 7) into x and y, then print their sum.

intermediate

Sum a list of 3 (['a', 'b', 'c'])

Print the sum of all numbers in [9, 3, 6].

intermediate

Word counts in a 3-item list (['up', 'up', 'down'])

Count each item in ['up', 'up', 'down'] into a dict and print it.

intermediate

Sort [2, 2, 2, 5]

Print [2, 2, 2, 5] sorted in ascending order.

intermediate

Unique values of [2, 2, 2, 5]

Print the unique values of [2, 2, 2, 5], sorted (use a set).

intermediate

Common items of two lists (['up', 'up', 'down'])

Print the sorted values present in BOTH [2, 2, 2, 5] and [5, 8, 2].

intermediate

Highest value's key (['up', 'up', 'down'])

In the dict {'s': 6, 't': 6}, print the key with the largest value.

intermediate

Unpack a tuple (3, 12)

Unpack (3, 12) into x and y, then print their sum.

intermediate

Sum a list of 4 (['up', 'up', 'down'])

Print the sum of all numbers in [2, 2, 2, 5].

intermediate

Sort [4, 2, 3, 2]

Print [4, 2, 3, 2] sorted in ascending order.

intermediate

Unique values of [4, 2, 3, 2]

Print the unique values of [4, 2, 3, 2], sorted (use a set).

intermediate

Common items of two lists (['red', 'blue', 'red'])

Print the sorted values present in BOTH [4, 2, 3, 2] and [3, 4, 5].

intermediate

Sum a list of 4 (['red', 'blue', 'red'])

Print the sum of all numbers in [4, 2, 3, 2].

intermediate

Sort [9, 5, 9]

Print [9, 5, 9] sorted in ascending order.

intermediate

Unique values of [9, 5, 9]

Print the unique values of [9, 5, 9], sorted (use a set).

intermediate

Common items of two lists (['x', 'y', 'x', 'z']·2)

Print the sorted values present in BOTH [9, 5, 9] and [5, 10, 2].

intermediate

Sum a list of 3 (['x', 'y', 'x', 'z'])

Print the sum of all numbers in [9, 5, 9].

intermediate

Sort [6, 6, 2, 3]

Print [6, 6, 2, 3] sorted in ascending order.

intermediate

Unique values of [6, 6, 2, 3]

Print the unique values of [6, 6, 2, 3], sorted (use a set).

intermediate

Common items of two lists (['cat', 'dog', 'cat']·2)

Print the sorted values present in BOTH [6, 6, 2, 3] and [6, 3, 8].

intermediate

Sum a list of 4 (['cat', 'dog', 'cat']·2)

Print the sum of all numbers in [6, 6, 2, 3].

intermediate

Sort [10, 4, 7]

Print [10, 4, 7] sorted in ascending order.

intermediate

Unique values of [10, 4, 7]

Print the unique values of [10, 4, 7], sorted (use a set).

intermediate

Common items of two lists (['a', 'b', 'c']·2)

Print the sorted values present in BOTH [10, 4, 7] and [7, 2, 4].