-2

enter image description here

Why do sets not maintain the insertion order if they are unordered data type?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • Sets don't have to maintain insertion order (or _any other order_) precisely _because_ they're an unordered data type, which makes your question quite confusing. (Also note from what I've seen geeksforgeeks is pretty low quality, try https://sopython.com/wiki/What_tutorial_should_I_read%3F) – jonrsharpe Aug 19 '23 at 07:55
  • The fact that they are unordered means you cannot (and should not) expect it to print out `{3,2,1}` (or any kind of order for that matter) – Gino Mempin Aug 19 '23 at 07:56
  • *"Why do sets not maintain the insertion order if they are unordered data type?"* - Because that would make them an ordered type ... where the order is the insertion order. (Ordered doesn't mean sorted. It actually just means that iterating the collection will return the elements in a *predictable* sequence.) – Stephen C Aug 19 '23 at 10:38

0 Answers0