It depends on what you are intending to do with it.

Sets are significantly faster when it comes to determining if an object is present in the set (as in x in s), but its elements are not ordered so you cannot access items by index as you would in a list. Sets are also somewhat slower to iterate over in practice.

You can use the timeit module to see which is faster for your situation.

Answer from Michael Aaron Safyan on Stack Overflow
Top answer
1 of 11
316

It depends on what you are intending to do with it.

Sets are significantly faster when it comes to determining if an object is present in the set (as in x in s), but its elements are not ordered so you cannot access items by index as you would in a list. Sets are also somewhat slower to iterate over in practice.

You can use the timeit module to see which is faster for your situation.

2 of 11
243

Lists are slightly faster than sets when you just want to iterate over the values.

Sets, however, are significantly faster than lists if you want to check if an item is contained within it. They can only contain unique items though.

It turns out tuples perform in almost exactly the same way as lists, except for their immutability.

Iterating

>>> def iter_test(iterable):
...     for i in iterable:
...         pass
...
>>> from timeit import timeit
>>> timeit(
...     "iter_test(iterable)",
...     setup="from __main__ import iter_test; iterable = set(range(10000))",
...     number=100000)
12.666952133178711
>>> timeit(
...     "iter_test(iterable)",
...     setup="from __main__ import iter_test; iterable = list(range(10000))",
...     number=100000)
9.917098999023438
>>> timeit(
...     "iter_test(iterable)",
...     setup="from __main__ import iter_test; iterable = tuple(range(10000))",
...     number=100000)
9.865639209747314

Determine if an object is present

>>> def in_test(iterable):
...     for i in range(1000):
...         if i in iterable:
...             pass
...
>>> from timeit import timeit
>>> timeit(
...     "in_test(iterable)",
...     setup="from __main__ import in_test; iterable = set(range(1000))",
...     number=10000)
0.5591847896575928
>>> timeit(
...     "in_test(iterable)",
...     setup="from __main__ import in_test; iterable = list(range(1000))",
...     number=10000)
50.18339991569519
>>> timeit(
...     "in_test(iterable)",
...     setup="from __main__ import in_test; iterable = tuple(range(1000))",
...     number=10000)
51.597304821014404
🌐
Quora
quora.com › What-is-the-difference-between-lists-arrays-and-sets-in-Python
What is the difference between lists, arrays, and sets in Python? - Quora
Answer: Lists: A built in type, with the following characteristics. * Variable length with a maximum of [code ]sys.maxsize[/code] elements * Elements can be anything - built in types, custom types, etc; * There is no requirement for elements to be hashable. * Elements can be repeated within...
🌐
GeeksforGeeks
geeksforgeeks.org › python › sets-vs-lists-python
Sets vs. Lists - Python - GeeksforGeeks
July 23, 2025 - The main difference is that lists are ordered, meaning the order of elements is preserved and they can be accessed by their index while sets are unordered meaning they do not maintain the order of elements and automatically ensure all elements are unique. This article will explore the differences between sets and lists, including their properties, performance, and typical use cases.
🌐
Reddit
reddit.com › r/learnpython › differences in terms of performance between list, set, and numpy arrays?
r/learnpython on Reddit: Differences in terms of performance between list, set, and numpy arrays?
May 12, 2024 -

I already know the major differences in terms of functionality and basic performance differences, such as sets are fastest for finding an elements existence, but I would like to know a more comprehension guide to which data type is faster for certain operations / under certain conditions. For example:

  • creation

  • small vs large number of elements

  • iteration

  • modification of elements

  • getting a specific index element value

Thanks!

Top answer
1 of 4
4
Accessing a single element in a list is 5x faster than accessing a single element in a numpy array, 22.1 ns rather than 123 ns on my pc. Lists are better for single-element operations. A one-million-element multiplication operation on a numpy array is 50x faster than the similar list-comprehension operation, 1.28 ms rather than 64.2 ms. Numpy arrays are better for array operations. (These figures are copied from a test I did about 5 years ago, i.e. before the Faster CPython project, but should still be mostly relevant. The ipython %%timeit has its setup on the first line and times the second line.) In [2]: %%timeit mylist = [1,2,3] ...: x = mylist[1] ...: 22.1 ns ± 0.0626 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each) In [3]: %%timeit import numpy; myarray = numpy.array([1,2,3]) ...: x = myarray[1] ...: 123 ns ± 0.0508 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each) In [4]: %%timeit mylist = list(range(1000000)) ...: newlist = list(n*2 for n in mylist) ...: 64.2 ms ± 704 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) In [5]: %%timeit import numpy; myarray = numpy.arange(1000000) ...: newarray = myarray * 2 ...: 1.28 ms ± 1.43 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
2 of 4
2
The breakeven point was arrays of size 10 or so when I tested it on some problem.  I consider 100,000x3 small for my array sizes.  It’s not even close.  Numpy is really good. That said, bad numpy code is worse than equivalent pure python code.  A for loop of a cross product implemented in python will be 2-3x faster than using numpy.  I’d still use it because I wouldn’t need to validate the formula.  That said, if you just vectorized it, it’d be 1000x faster. If you’re going to scale, you might as well start with numpy even if it’s slower right now.  As you get better, you’ll just write vectorized code and have fewer things to fix when it’s deemed too slow.
🌐
LinkedIn
linkedin.com › pulse › what-difference-between-lists-arrays-sets-python-sajith-madhubashana
What is the difference between lists, arrays, and sets in Python?
February 20, 2023 - 264–1 (unsigned long long), although Python integers are effectively unlimited (and therefore considerably larger than the array can hold). ... A built in type, with the following characteristics. Variable length with a maximum of sys.maxsize elements · Elements can be any value or object so long as they are hashable; so for instances strings, numbers and tuples can be placed in a set, but lists, dictionaries for instance cannot be.
🌐
DevOpsSchool.com
devopsschool.com › blog › python-tutorials-difference-between-list-array-tuple-set-dict
Python Tutorials: Difference between List & Array & Tuple & Set & Dict
Unordered means the elements are not ordered therefore cannot be indexed. Unique means that a set cannot store duplicate values and are therefore very handy for removing duplicates from lists. You can store any python objects in a set.
🌐
GeeksforGeeks
geeksforgeeks.org › difference-between-a-set-and-an-array
Difference Between a Set and an Array
February 1, 2024 - Python · JavaScript · Data Science · Machine Learning · Courses · Linux · DevOps · While you’re here, feast your eyes upon these popular · recommendations for you. Problem of the dayKnow more >> Courses @90% RefundAvail Now!
Find elsewhere
🌐
DataCamp
datacamp.com › tutorial › sets-in-python
Python Sets Tutorial: Set Operations & Sets vs Lists | DataCamp
December 13, 2022 - The code below outputs the values in the set dataScientist in descending alphabetical order (Z-A in this case). ... Part of the content in this section was previously explored in the tutorial 18 Most Common Python List Questions, but it is important to emphasize that sets are the fastest way to remove duplicates from a list.
🌐
freeCodeCamp
freecodecamp.org › news › python-set-vs-list
Python Set VS List – Sets and Lists in Python
January 5, 2023 - To create a set in Python, you can use the set() constructor or curly braces.
🌐
GitConnected
levelup.gitconnected.com › list-vs-set-in-python-4ea183dfe20c
List vs. Set in Python. What are the differences between lists… | by Roi Yehoshua, PhD | Level Up Coding
August 3, 2023 - List vs. Set in Python What are the differences between lists and sets and when to use each one? Lists and sets are both built-in data structures in Python that can store collections of objects …
Top answer
1 of 1
1
From my understanding: Arrays are a thin wrapper on C style arrays. They can only contain objects of the same basic data-type, so they are more strongly typed - but they can only deal with numeric C-style data types. They are a lot more basic than lists or sets. Arrays are probably best used in situations where you know up front, how many items they will contain and that the array will not need to grow. But if you're going to be dealing with a dynamic set of data that could grow or shrink - you're probably better off using List or Set. · Sets can hold pretty much anything - as long as it is hashable. Objects in the set are sorted/ordered based on each objects hash values. Also, sets do not allow duplicates. And I'm not sure how set deals with hash collisions (where two different objects have the same hash-values). And because sets use hash-tables, lookups are pretty fast. So if you are dealing with hashable types and you don't want duplicates (and you aren't worried about possible hash-collisions) - sets are the way to go. · Lists can hold pretty much anything and don't care about duplicates. Objects remain in the order in which they were added. If a list runs out of space and needs to reallocate - it will reallocate much more space than it needs. So lists can become quite large. But this does mean that they can be appended to efficiently, because reallocations will occur less often. · So to sum up: Lists should be adequate for most uses - especially if it is possible that the data-set will grow to be large. Arrays are really only useful for numeric data. Sets can only be used with hashable types, with no duplication. · https://docs.python.org/3/library/array.html#module-arrayhttps://wiki.python.org/moin/TimeComplexityhttps://docs.python.org/3/glossary.html#term-hashable
🌐
YouTube
youtube.com › watch
Python Lists vs Tuples vs Sets - Visually Explained - YouTube
🔵 Resources & Further Learning- 📒 Practice notebook → https://colab.research.google.com/drive/1WkXQ7hEd74Dj-suqkFvn4guygwADv2Xy- 📒 Practice notebook solut...
Published: August 12, 2025
🌐
Javatpoint
javatpoint.com › set-vs-list-in-python
Set vs List in Python
Difference between Set and List in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
🌐
Stack Overflow
stackoverflow.com › questions › 70029636 › difference-between-array-and-sets
Difference between Array and Sets - Stack Overflow
The difference between sets and array sis not a programming question, but a question about data structures. Also, the subject had been treated many times before, you are are expected to do some search before asking.
🌐
W3Schools
w3schools.com › python › python_sets.asp
Python Sets
Sets are used to store multiple items in a single variable.
🌐
Medium
zlliu.medium.com › python-lists-vs-dicts-vs-sets-vs-tuples-dc784d1e0daf
Python — Lists VS Dicts VS Sets VS Tuples | by Liu Zuo Lin | Medium
September 5, 2024 - I recently went back to school, and have to take a compulsory Python programming module. Which has been reinforcing my absolute basics once again (it’s been 7 years) And one topic that has been confusing my classmates who are new to programming is: when to use lists VS dicts VS sets VS tuples
🌐
Jerry Ng
jerrynsh.com › tuples-vs-lists-vs-sets-in-python
Tuples vs. Lists vs. Sets in Python - Jerry Ng
August 9, 2021 - In Python, there are four built-in data types that we can use to store collections of data. With different qualities and characteristics, these built-in data types are List (list), Tuple (tuple), Set (set), and Dictionary (dict).