Python: When to Use Set vs. List

March 30, 2021

For many Python programmers, we love to use lists to store data, but when should you choose to use a data structure like a set over a list? The answer is that when it comes to determining if an item is in a data structure, a set is a lot faster than a list. However, when it comes to looping through a data structure, a list is faster. Of course, a list has order, but a set does not, therefore no index either.