1 import unittest
   2 
   3 class SeqDict(dict):
   4     """dictionary that perserve the setted sequence
   5     """
   6     def __init__(self):
   7         self._seq=list()
   8     def __setitem__(self, key, value):
   9         self._seq.append(key)
  10         dict.__setitem__(self, key, value)
  11     def keys(self):
  12         return self._seq
  13     def values(self):
  14         result=list()
  15         for key in self.keys():
  16             result.append(self[key])
  17         return result
  18 
  19 class SeqDictTest(unittest.TestCase):
  20     def test1(self):
  21         sd = SeqDict()
  22         sd['one'] = 1
  23         sd['two'] = 2
  24         sd['three'] = 3
  25         self.assertEquals(['one','two','three'], sd.keys())
  26         self.assertEquals([1,2,3], sd.values())
  27 
  28 class ValueSizedSeqDict(SeqDict):
  29     """To be continue..."""
  30 
  31 if __name__=='__main__':
  32     unittest.main(argv=('','-v'))
web biohackers.net