So I am very new to python and I cant for the life of me figure out why these two statements evaluate differently,
[3*x for x in range(1,11) if x > 5]
[18, 21, 24, 27, 30]
{3*x for x in range(1,11) if x > 5}
set([24, 18, 27, 21, 30])
The top one makes perfect sense to me but why does the second print things in such a weird order? I know that hard brackets '[' are for lists and '{' for dictionaries.
The second one is not a dictionary but a set. Both sets and dictionaries are unordered. The elements are not stored or displayed with any particular meaningful order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With