Python: Iterate alphabetically over OrderedDict
Question: In a script I have an OrderedDict `groups` that gets fed key/value pairs
alphabetically.

In another part of the script, I'm checking against files that have the same
same as `key` like so:

    
    
    for (key, value) in groups.items():        
        file = open(key, 'r') 
        # do stuff
    

Stuff happens just fine, part of which is printing a status line for each
file, but how can I get Python to iterate through `groups` alphabetically, or
at least numerically as they are ordered (since they are being entered in
alphabetical order anyways)?


Answer: The whole point of an `OrderedDict` is that you can iterate through it
normally in the order that keys were entered:

    
    
    >>> from collections import OrderedDict
    >>> d = OrderedDict()
    >>> d[1] = 2
    >>> d[0] = 3
    >>> d[9] = 2
    >>> for k, v in d.items():
            print(k, v)
    
    
    (1, 2)
    (0, 3)
    (9, 2)
    

Just make sure you don't feed `OrderedDict(...)` a dictionary to initialize it
or it starts off unordered.

