0

I wanted to understand logic behind set().

Program :

A={500,520,600,345,520,634,600,500,200,200}
print ("Set A = ",A)

B={10,20,60,345,50,600,500,200,200}
print ("Set B = ",B)

print ("Set A | Set B = ", A|B)

Output :

Set A =  {520, 200, 500, 600, 345, 634}
Set B =  {200, 10, 50, 20, 500, 600, 345, 60}
Set A | Set B =  {520, 200, 10, 50, 500, 20, 600, 345, 634, 60}

How set decide in which sequence output should be displayed.

namz
  • 1
  • 1
  • Set ordering is essentially random. There is no guaranteed order. – John Gordon Apr 21 '22 at 14:56
  • Strictly speaking, there is no logic. It's implementation defined, and Python could simply pick a random order each time it iterates over a set if it wanted to. – chepner Apr 21 '22 at 14:56

0 Answers0