I am bit confused. It starts like this.
- You can add element into empty set using
add()
method. - Sets doesn't maintain the order in which the elements are added to set.
a=set() b=[4,2,3] for i in b: a.add(i)
Expected output is set([4, 2, 3])
But actual output is
C:\Users\dinesh_pundkar\Desktop>python dsp.py
set([2, 3, 4])
So I thought/assume, after adding element to set it got sorted that's why output is set([2,3,4])
.
Now, I added alphabet 'A'
to above set and output is set(['A', 2, 3, 4])
.
To check whether this sorted or not, I created a list b = ['A', 2, 3, 4]
and sorted it.
Eureka !!! Sorted list is [2,3,4,'A']
.
So, that's why I am confused.
Requesting all to help me understand this or what I am missing.