I thought i found away to sort a dictionary by clearing it then reassemble it in the order i wanted but for some reason it reorders itself the way it started out.
Here is the code if somebody can help me out
from operator import itemgetter
n = {}
d = {
'a': ['2', 'ova', 'no'],
'b': ['23', 'movie', 'yes'],
'c': ['5', 'show', 'yes'],
'd': ['17', 'ova', 'yes'],
'e': ['1', 'movie', 'no']
}
for i in d:
print i, d[i]
print '\n'
l = d.items()
l.sort(key=itemgetter(1)) #l is now sorted by the value of the string holding the integers
d.clear()
for i in l:
print i[0], i[1]
d[i[0]] = i[1]
print '\n'
for i in d:
print i, d[i] #Why does the dictionary come out to be the same it started from
As Jon points out, dictionaries have no order. You get fast lookups by giving up ordering. You might not need it to keep an order though, since you have a sort order you like: