update method for dictionaries-Python
<p>I have written a code which tries to sort a dictionary using the values rather than keys</p>

<pre><code>""" This module sorts a dictionary based on the values of the keys"""

adict={1:1,2:2,5:1,10:2,44:3,67:2} #adict is an input dictionary 
items=adict.items()## converts the dictionary into a list of tuples

##print items

list_value_key=[ [d[1],d[0]] for d in items] """Interchanges the position of the 
                                                key and the values"""
list_value_key.sort()
print list_value_key

key_list=[ list_value_key[i][1] for i in range(0,len(list_value_key))]

print key_list  ## list of keys sorted on the basis of values 

sorted_adict={}

*for key in key_list:
    sorted_adict.update({key:adict[key]})
    print key,adict[key]

print sorted_adict*
</code></pre>

<p>So when I print key_list i get the expected answer, but for the last part of the code where i try to update the dictionary, the order is not what it should be. Below are the results obtained. I am not sure why the "update" method is not working. Any help or pointers is appreciated</p>

<p>result:</p>

<pre><code>sorted_adict={1: 1, 2: 2, 67: 2, 5: 1, 10: 2, 44: 3} 
</code></pre>
