0

Suppose I have a dictionary:

masterdict = {'28': ['28057', '28095', '28033'], '04': ['04025'], '24': ['24023']}

I simply want to iterate through each item in order. It was doing so before, and now seems to start at '24', then '28' and '04'. Why would this be happening?

 for sFips, cFipsList in masterdict.iteritems():
    print sFips
    print cFipsList    
gwydion93
  • 1,681
  • 3
  • 28
  • 59
  • 4
    dictionaries are not ordered in python 2 – sacuL Nov 04 '18 at 01:30
  • 1
    You want the `collections.OrderedDict` https://docs.python.org/2/library/collections.html#collections.OrderedDict , not just a regular dict. For Python 3, dictonaries are ordered in insertion order, but in Python 2, that is not necessarily true. – Casey Kuball Nov 04 '18 at 02:59

0 Answers0