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:
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.
a = set([3, 2, 1]) print(a)prints: {1, 2, 3}
a = set([1, 2, 3]) print(a)prints: {1, 2, 3}
a = set([5, 7, 9]) print(a)prints: {9, 5, 7}
a = set([7, 9, 5]) print(a)prints: {9, 5, 7}
a = set([5, 3, 7]) print(a)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.