PyPython · Lesson 5 of 14
Lists, Dicts & Sets
Python's built-in collections are so good you'll rarely need anything else. Lists, dicts, and sets cover 95% of real-world needs.
Lists are ordered, mutable sequences. They're Python's workhorse collection type. You can put anything in a list — including other lists.
Dictionaries map keys to values. As of Python 3.7+, they maintain insertion order. They're used everywhere — for config, JSON-like data, and anything that needs fast key-based lookup.
◆ Note
Use a list when order matters. Use a dict when you need to look things up by name. Use a set when you only care about unique membership. Picking the right data structure is half of writing good code.
Use a list when order matters. Use a dict when you need to look things up by name. Use a set when you only care about unique membership. Picking the right data structure is half of writing good code.