0
s1 = {True, "Earth", "Sky", 25, -6.555, 9-5j, 25, "Sky", 25}

o/p = {(9-5j), -6.555, 25, 'Earth', 'Sky', True}

s2 = {"hi", -2+5j, 60, -6}

o/p = {(-2+5j), -6, 60, 'hi'}

can anyone help why they follow that type of order

pika
  • 1
  • 2
  • @TurePålsson thanks for your response yes the link can be answer but that I did not understand if anyone can clearly explain then it will be helpful – pika May 06 '22 at 06:40
  • @TurePålsson That answer is about Python 2. And OP's output is from Python 3. So not a duplicate. – BoarGules May 06 '22 at 06:42

1 Answers1

0

Set are unordered as they stores values in hash table. The sequence of values solemnly depends on the execution machine. I had executed the code got different results from yours.

https://ide.geeksforgeeks.org/e8808c91-0a5b-4dff-9caf-1da0f8be2142

enter image description here


Happy coding :)

  • https://stackoverflow.com/users/4982185/mohit-atul in your output print is mentioned for that is why it giving that type result but if you just execute s2 or s1 then you get what I get also and why is there the difference also when we mention print o/p is different and when we did not put print o/p is another, kindly explain. – pika May 06 '22 at 07:24
  • Hi, I've executed in ubuntu python also, its giving different results everytime with other python instances for example. ` Python 3.7.12 (default, Mar 23 2022, 15:01:04) [GCC 8.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> s1 = {True, "Earth", "Sky", 25, -6.555, 9-5j, 25, "Sky", 25} >>> s2 = {"hi", -2+5j, 60, -6} >>> s1 **{True, 'Sky', 'Earth', (9-5j), 25, -6.5549999999999997}** >>> s2 **{-6, 'hi', 60, (-2+5j)}** ` – Mohit Atul May 06 '22 at 09:18