+ 1
Why is it faster to check if an element is part of a set than a list?
The tutorial says that the reason is the way sets are stored. But I want a more detailed explanation.
1 Respuesta
+ 2
Because set contains only uniques while list can contain duplicate. So it is faster to search through set.
list=[1,2,3,2]
a=set(list)
print(a)
Output:
{1,2,3} or {2,1,3} as sets are not indexed.