code_junkie

Sorting a dict on __iter__

Nov 11th, 2011
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. def itersorted(d):
  2. for key in sorted(d):
  3. yield d[key]
  4.  
  5. def sorted_dict(d):
  6. keys = d.keys()
  7. keys.sort()
  8. for key in keys:
  9. yield d[key]
  10.  
  11. def sortedDict(dictobj):
  12. return (value for key, value in sorted(dictobj.iteritems()))
  13.  
  14. def compareTwo(a, b):
  15. if a > b:
  16. return 1
  17. if a == b:
  18. return 0
  19. if a < b:
  20. return -1
  21.  
  22. List.Sort(compareTwo)
  23. print a
Add Comment
Please, Sign In to add comment