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) | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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)

10th Aug 2016, 10:36 PM
ā€«Ido Tal
ā€«Ido Tal - avatar
5 Respostas
+ 2
I think the elements in a set has no order.
11th Aug 2016, 1:45 AM
Yuyang Songsheng
Yuyang Songsheng - avatar
+ 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.
15th Sep 2016, 12:45 AM
Jonathan Rice
Jonathan Rice - avatar
0
but I write it in some order, why it change that?
11th Aug 2016, 9:52 AM
ā€«Ido Tal
ā€«Ido Tal - avatar
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.
19th Sep 2016, 9:30 PM
Juan Pablo Giuttari
Juan Pablo Giuttari - avatar
0
i think thats not important just try in code area
4th Dec 2016, 2:16 PM
MANICKAM . R
MANICKAM . R - avatar