+ 3
Can anyone please explain why the output of this operation print(second - first) is {8, 9, 7} not {7, 8, 9} ?
first = {1, 2, 3, 4, 5, 6} second = {4, 5, 6, 7, 8, 9} print(first | second) print(first & second) print(first - second) print(second - first) print(first ^ second)
4 Respuestas
+ 3
sets are unordered. They are NOT made to support order, but uniqueness.
If you want really want order, try using a different data structure.
0
I was just about to ask the same thing... Thanks.
0
@Amaras A
I understand that sets are not ordered, but why out of the entire program does just the 7 specifically go to the end whilst all other numbers are printed ordered?
Could it be that the print function orders the set before printing it but something prevented it from ordering the 7?
It seems strange...
0
They are not ordered, there is no way to really know which way the values will go. That's just the way it is