Use Sets to Improve Python Performance

Curt Beck
Level Up Coding
Published in
3 min readOct 16, 2022

--

Photo by Nicolas Hoizey on Unsplash

One of the first concepts I’ve learned in Python were lists and iterating over them. Lists are undoubtedly a very important concept, but I often find myself over-relying on them, especially in the case of membership tests (checking if one element from one list is in another), which can negatively impact performance runtime. Depending on the situation, different datatypes, such as sets, may be a more optimal solution.

--

--

Stumbled into a data-centric role several years ago and have not looked back! Passionate about leveraging technology to uncover answers and improve the world.