Set is an unordered data structure

What does it really mean when we say that set is an unordered data structure???
Now if we deduplicate any list by this process in python:
a = [1, 2, 2, 1, 2. 1, 1, 2, 2]
b = list(set(a))
b
In the lecture, it is told that in this process we cant assure whether the order or the indexing of the elements in list b is retained as it was in the list a or not as the set is an unordered dataset.
Will you please elaborate on this in a little bit more detail??

hey @bihan ,
yes sets are unordered.
So actually the thing is , the reason why it is called unordered is that you can access using index , because sets doesn’t maintain any order of the items.
but if you try to print or loop over it , then you will the values in a sorted manner , that is actually a functionality of it.

So , this is the only reason for that.

I hope this helps.

1 Like

Do you mean… it can’t be accessed using an index???

yeah, it can’t be accessed.
try it , a[1]

1 Like


I tried looping over the set , but why 74 came before 54?

set got sorted when i tried iterating over the set but you see what happend 74 came before 54…why so?

Although it shouldn’t be , but still as it there , so no idea bro about this.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.