I am having a hard time writing a class, which should be able to iterate through a sorted dicitonary. My main problem is at the iter-overload. I don't how to get the dic sorted.
class SortedDict():
def __init__(self, dic = None):
self.dic = {}
if len(dic) > 0: self.dic = dic;
def __iter__(self):
self.dic = sorted(self.dic.keys())
self.index = 0
return self
def next(self):
if self.index+1 < len(self.dic):
self.index += 1
return self.dic.keys()[self.index]