difference between lists and sets

0 votes
Are there any other difference between sets and lists in Python other than the use of the union, intersect, difference, symmetric difference functions to compare two sets? Why can't these functions simply be applied to lists? In what situations are sets more useful than lists?
Jan 7, 2019 in Python by ana1504.k
• 7,910 points
598 views

1 answer to this question.

0 votes
There are a lot more differences such as :

1. Sets can't contain duplicates
2. Sets are unordered
3. In order to find an element in a set, a hash lookup is used (which is why sets are unordered). This makes __contains__ (in operator) a lot more efficient for sets than lists.
4. Sets can only contain hashable items.
 

In practical applications, lists are very nice to sort and have order while sets are nice to use when you don't want duplicates and don't care about order.
answered Jan 7, 2019 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer

What is the difference between sets and lists in Python?

Lists can contain duplicates but sets cannot Sets ...READ MORE

answered Feb 9, 2022 in Python by Dev
• 6,000 points
711 views
0 votes
1 answer

Difference between del, remove and pop on lists

es, remove removes the first matching value, ...READ MORE

answered Aug 1, 2018 in Python by Priyaj
• 58,090 points
800 views
0 votes
5 answers
0 votes
2 answers

What is the difference between python lists and arrays?

Python arrays and lists have the same ...READ MORE

answered Jun 11, 2019 in Python by Nisa
• 1,090 points
1,093 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,067 views
0 votes
1 answer
0 votes
2 answers

difference between class and instance attributes

Apart from the performance, there is a ...READ MORE

answered Sep 17, 2018 in Python by SDeb
• 13,300 points
677 views
0 votes
1 answer

Difference between module and Package in Python

A module is basically a single file ...READ MORE

answered Nov 13, 2018 in Python by SDeb
• 13,300 points
2,142 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP