set and dict are not ordered
β’ 61 words β’ 1 min β’ updated
Sets and dictionaries are not ordered.
python
>>> for n in set([3,1,2,-1]): print(n)
...
1
2
3
-1If you want the set to be ordered, use sorted:
python
>>> for n in sorted(set([3,1,2,-1])): print(n)
...
-1
1
2
3This is unlike C++’s set:
std::setis an associative container that contains a sorted set of unique objects of type Key.