How to implement associative array (not dictionary) in Python?
Question: I trying to print out a dictionary in Python:

    
    
    Dictionary = {"Forename":"Paul","Surname":"Dinh"}
    for Key,Value in Dictionary.iteritems():
      print Key,"=",Value
    

Although the item "Forename" is listed first, but dictionaries in Python
**seem to be** sorted by values, so the result is like this:

    
    
    Surname = Dinh
    Forename = Paul
    

How to print out these with the same order in code or **the order when items
are appended in** (not sorted by values nor by keys)?


Answer: First of all dictionaries are not sorted at all nor by key, nor by value.

And basing on your description. You actualy need
[collections.OrderedDict](http://docs.python.org/library/collections.html#collections.OrderedDict)
module

    
    
    from collections import OrderedDict
    
    my_dict = OrderedDict([("Forename", "Paul"), ("Surname", "Dinh")])
    
    for key, value in my_dict.iteritems():
        print '%s = %s' % (key, value)
    

Note that you need to instantiate `OrderedDict` from list of tuples not from
another dict as dict instance will shuffle the order of items before
OrderedDict will be instantiated.

