Jul-10-2020, 08:04 PM
I am coming learning python after working with c++ for a few years. In c++ when you insert into a set it orders the elements, I can't figure out why in python sometimes the set will order the elements and sometimes it does not. Here are a few examples:
prints: {1, 2, 3}
prints: {1, 2, 3}
prints: {9, 5, 7}
prints: {9, 5, 7}
prints: {3, 5, 7}
I don't know what's going on here, I know you can sort the set using sorted() but the way it originally stores the information doesn't make any sense to me.
1 2 |
a = set ([ 3 , 2 , 1 ]) print (a) |
1 2 |
a = set ([ 1 , 2 , 3 ]) print (a) |
1 2 |
a = set ([ 5 , 7 , 9 ]) print (a) |
1 2 |
a = set ([ 7 , 9 , 5 ]) print (a) |
1 2 |
a = set ([ 5 , 3 , 7 ]) print (a) |
I don't know what's going on here, I know you can sort the set using sorted() but the way it originally stores the information doesn't make any sense to me.