+ 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)

8th Oct 2016, 3:58 AM
Mena Khalaf Louis
Mena Khalaf Louis - avatar
4 Respostas
+ 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.
9th Oct 2016, 9:58 PM
Amaras A
Amaras A - avatar
0
I was just about to ask the same thing... Thanks.
7th Feb 2017, 12:02 AM
m
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...
7th Feb 2017, 12:05 AM
m
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
11th Feb 2017, 7:58 PM
Amaras A
Amaras A - avatar