+ 1
why the code second-first print 8,9,7 and not 7,8,9? first = {1, 2, 3, 4, 5, 6} second = {4, 5, 6, 7, 8, 9} print(second - first)
5 Réponses
+ 2
I think the elements in a set has no order.
+ 1
It changes the order because the computer doesnt keep track of the order of elements in the set as it writes to memory. The output is the order in memory and not the order specified.
0
but I write it in some order, why it change that?
0
Sets order its elements for speed when looking for them. You cannot rely on that its order will be maintained. If order IS important, then you must use a list. Sets (and Dictionaries) use a hashtable internally, and it has its own logic for ordering, but we shouldn't worry about it.
0
i think thats not important
just try in code area