As already mentioned, dicts does not order or order the elements you insert. This is βmagicβ as to how it is ordered when it is received. If you want to keep the order sorted or not, you also need to bind a list or tuple.
This will give you the same dict result with a list that keeps order:
greek = ['beta', 'gamma', 'alpha'] d = {} for x in greek: d[x[0]] = x
Just change [] to () if you don't need to change the original list / order.
source share