There\'s an existing function that ends in the following, where d is a dictionary:
d
return d.iteritems()
that returns an unsort
Use the sorted() function:
return sorted(dict.iteritems())
If you want an actual iterator over the sorted results, since sorted() returns a list, use:
sorted()
return iter(sorted(dict.iteritems()))