0

My Python code:

ls1=[2,3,6,6,4]
v=set(ls1)
print(v)               # o/p : set([2, 3, 4, 6])

ls3=[9,13,14,7,6,5]
z=set(ls3)
print(z)               # o/p : set([5, 6, 7, 9, 13, 14])

but in this case its not going to work !

ls2=[8,7,6,5,4]
q=set(ls2)
print(q)               # o/p : set([8, 4, 5, 6, 7])

why??

juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
SAGY
  • 67
  • 7

1 Answers1

0

A Set is an unordered collection data type that is iterable, mutable, and has no duplicate elements. Python’s set class represents the mathematical notion of a set. The major advantage of using a set, as opposed to a list, is that it has a highly optimized method for checking whether a specific element is contained in the set. This is based on a data structure known as a hash table.

Sets in Python