PyCon UK 2025

Beyond lists: why other collection types are often better
2025-09-19 , Main stage

Lists are everywhere in Python. But are they always the best tool for the job? Find out why tuples, sets and frozensets are often a better choice when working with collections.


When writing Python, we often to need to work with a collection of objects. And so often we reach for the humble list. But lists, while they can get the job done, are often not the best choice.

Do you really need that collection to change? If you don't, picking a tuple instead will bring unexpected benefits. Or is the order of the elements important? If not, then using a set will open up a world of new possibilities. And if your set doesn't need to change, then consider a frozenset - Python's most underrated built-in data structure.

Equipped with these data structures, we'll close by looking at the subtleties of how to type-annotate functions, and why on earth it is better to use Set (with a capital 'S') for an argument type, but set for the return type.

It's time to go beyond lists!


What level of experience do you expect from your audience for this session?:

Basic

David Seddon works in London at Kraken Tech, the technology tentacle of Octopus Energy. There, he works on a very large Django monolith consisting of tens of thousands of Python modules. He’s also a member of the Django Software Foundation.

He loves thinking about and teaching software design, in particular domain modelling and application architecture.

He is the creator of Import Linter, an open-source tool to check your Python project is following a set of architectural rules you define.

He blogs at https://seddonym.me.