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
🌐
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...
🌐
W3Schools
w3schools.com › python › python_arrays.asp
Python Arrays
Python has a set of built-in methods that you can use on lists/arrays. Note: Python does not have built-in support for Arrays, but Python Lists can be used instead. ... Coding fundamentals as bite-sized lessons and challenges. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
Discussions

Python Sets vs Lists - Stack Overflow
In Python, which data structure is more efficient/speedy? Assuming that order is not important to me and I would be checking for duplicates anyway, is a Python set slower than a Python list? More on stackoverflow.com
🌐 stackoverflow.com
Why we use SET instead of using array?? , it says both are same but i feel set a little bit uncomfortable? is there any idea of using SET? I want to know some cool fact about using set?
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends. More on sololearn.com
🌐 sololearn.com
4
8
The difference between arrays sets and objects?
cyber voyager is having issues with: This question emphasizes on sets, could you explain the differences between these 3? Why would I use one instead of the other? Thank you... More on teamtreehouse.com
🌐 teamtreehouse.com
3
June 16, 2017
Are arrays and lists essentially the same?
“Array” is an ambiguous term in Python and best not used. Most beginners use it to refer to the list type, but are unaware that there is actually an array.array type in the standard library as well. More on reddit.com
🌐 r/learnpython
41
32
May 7, 2022
🌐
DevOpsSchool.com
devopsschool.com › blog › python-tutorials-difference-between-list-array-tuple-set-dict
Python Tutorials: Difference between List & Array & Tuple & Set & Dict
October 13, 2022 - 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.
🌐
W3Schools
w3schools.com › python › python_sets.asp
Python Sets
Sets are used to store multiple items in a single variable.
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
🌐
W3schools
w3schools.dev › python › python_arrays.asp
Python Arrays - W3Schools
Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary · Random Module Requests Module Statistics Module Math Module cMath Module · Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Server Python Interview Q&A Python Bootcamp Python Certificate ... Note: Python does not have built-in support for Arrays, but Python Lists can be used instead.
🌐
freeCodeCamp
freecodecamp.org › news › python-set-vs-list
Python Set VS List – Sets and Lists in Python
January 5, 2023 - Sets and lists are built-in data structures you can use to store and arrange values in Python. If you're wondering which to use, it depends on the use case. If you don’t want the values in the data to change, you can use a set. But if you want the items to change, you can use a list.
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.
🌐
GeeksforGeeks
geeksforgeeks.org › difference-between-a-set-and-an-array
Difference Between a Set and an Array
February 1, 2024 - Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
🌐
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.
🌐
DevOps.dev
blog.devops.dev › how-i-choose-between-python-arrays-lists-tuples-sets-and-dictionaries-3f08a7c4513f
How I Choose Between Python Arrays, Lists, Tuples, Sets, and Dictionaries | by Sanim Khan | DevOps.dev
August 12, 2024 - Arrays: Best for collections of the same type where memory efficiency is a must. Lists: Ideal for dynamic collections with mixed types. Tuples: Great for fixed, unchangeable collections.
Top answer
1 of 3
5
You state a valid question. In fact, in many programming languages Objects like in javascript are called associative arrays. Meaning - you access the individual properties by 'associating' a value with a key. Regular arrays are 'Indexed Arrays' where as you already know you access individual properties by their index. So the major difference between the two is that a regular array is indexed, where an object contains associations.
2 of 3
2
To add on to what others have stated, this is just the language developing to more intuitively handle complex interactions. As software development deals with harder problems, people who write software end up finding patterns in the logic of their solutions. These patterns become recognized and used widely by other developers to make their software creation easier. As these patterns get reused over and over, the people who decide what goes into a language sometimes incorporate those patterns and they become part of the core of the language's capabilities. All computer programs do, essentially, is flip switches on and off (1 and 0). But we don't write programs by writing out huge series of 1s and 0s (at least, most people don't). These higher level abstractions like Boolean, Number, Array, Associative Array, Set, and so on are the evolution of the programming languages dealing with more and more complex problems. It is certainly easier to write `var x = 5' than to write out the huge string of binary digits that the computer's transistors ultimately encode. It is also easier to use these higher level abstractions of data types (Number, Array, etc) to write solutions to more complex problems. Long story short: Sets are used to store data types that should NOT be duplicated. There are a lot of math operations that rely on sets and knowing about those can help you design systems that use large amounts of data reliably. MDN quote: The Set object lets you store unique values of any type, whether primitive values or object references.
🌐
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).
🌐
W3Schools
w3schools.com › python › python_dsa_lists.asp
Python Lists and Arrays
In the example above, the time the algorithm needs to run is proportional, or linear, to the size of the data set. This is because the algorithm must visit every array element one time to find the lowest value. The loop must run 5 times since there are 5 values in the array.
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.15.0 documentation
Python also includes a data type for sets. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries.
🌐
Stack Overflow
stackoverflow.com › questions › 70029636 › difference-between-array-and-sets
Difference between Array and Sets - Stack Overflow
I don't understand the difference between Arrays and Sets. What is the difference between sets and arrays in python and where does numpy appear in arrays?
🌐
W3Schools
w3schools.com › python › python_lists.asp
Python Lists
There are four collection data types in the Python programming language: List is a collection which is ordered and changeable. Allows duplicate members. Tuple is a collection which is ordered and unchangeable. Allows duplicate members. Set is a collection which is unordered, unchangeable*, and unindexed.
🌐
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 …