Python dictionaries do not have an order guarantee.
This is because the dictionary is a hash map, and the hash map has its own key order determined by the hash function (which must be pseudo-random).
So, although you can access the first and last items in the dictionary ( NumberTextSet3.items()[0] and NumberTextSet3.items()[-1] , respectively), they probably do not correspond to the order in which you created the dictionary .
However, the standard library provides collections.OrderedDict , which preserves the insertion order, hence
from collections import OrderedDict NumberTextSet3 = OrderedDict(( ("ten", 10), ("hundred", 100), ("thousand", 1000), ("million", 1000000), ("billion", 1000000000), ("trillion", 1000000000000) )) print(list(NumberTextSet3.keys())) => ['ten', 'hundred', 'thousand', 'million', 'billion', 'trillion'] print(list(dict(NumberTextSet3).keys())) => ['million', 'hundred', 'ten', 'billion', 'thousand', 'trillion']
Remember that I am changing the dictionary literal to a list of tuples. Using a dictionary literal would not work, since it would create a temporary, disordered dictionary and pass it to an OrderedDict to freeze the (quasi-random) order.