Module 4: Python Data Structures

Beginner 16 chapters

40. Introduction to Lists

Meet the Python list: an ordered, changeable collection that can hold many values. Learn how to create one, read items, change them, add items and loop over a list.

Beginner20 min

41. List Creation and Indexing

Learn the different ways to create lists, including list(), range() and repetition, and master positive and negative indexing, nested lists and the IndexError.

Beginner20 min

42. List Methods

Learn the main list methods: append, insert, extend, remove, pop, sort, reverse, index and count, and understand which ones change the list and what they return.

Beginner20 min

43. List Slicing

Learn how to cut pieces out of a list with the start:stop:step slice syntax, use negative indexes, reverse a list, and assign to slices.

Beginner25 min

44. Nested Lists

Learn how to store lists inside lists, read and change items with two indexes, loop over rows and columns, and avoid the shared-row trap.

Beginner25 min

45. List Comprehension

Learn list comprehensions: build new lists in one readable line with a loop, an optional if filter, an if-else expression, and nested loops.

Beginner25 min

46. Introduction to Tuples

Meet the tuple, an ordered collection that cannot be changed: how to create it, index and slice it, unpack it, and decide when to choose it over a list.

Beginner25 min

47. Tuple Methods

Learn the two tuple methods, count and index, and the built-in functions and operators that work with tuples, such as len, min, max, sum, sorted, + and *.

Beginner25 min

48. Tuple Packing and Unpacking

Learn how to pack values into a tuple and unpack them into variables, including swapping, star unpacking, nested unpacking, and returning several values from a function.

Beginner25 min

49. Introduction to Sets

Meet the set: an unordered collection of unique, hashable items. Learn how to create sets, remove duplicates, test membership quickly, and use the basic set operators.

Beginner25 min

50. Set Methods

Learn the methods of a set: add, update, remove, discard, pop, clear, copy, the set-algebra methods, the update variants, and the subset and superset tests.

Intermediate30 min

51. Set Operations

Learn how to combine and compare sets with union, intersection, difference and symmetric difference, using both operators and methods.

Beginner25 min

52. Introduction to Dictionaries

Learn what a dictionary is, how to create one, read values by key, add and change entries, delete them, and loop over keys and values.

Beginner25 min

53. Dictionary Methods

Learn the most useful dictionary methods: get, setdefault, update, pop, popitem, keys, values, items, copy, clear and the merge operators.

Beginner25 min

54. Nested Dictionaries

Learn how to store dictionaries inside dictionaries, read and change deeply stored values safely, and loop over nested data such as student records or settings.

Beginner25 min

55. Dictionary Comprehension

Learn to build dictionaries in one readable line with dictionary comprehensions, including filtering, transforming, swapping keys and values, and combining two lists.

Beginner25 min

Take the module test