Made the constructor take dictionaries.

This commit is contained in:
Jeremy Fincher 2003-10-16 19:40:14 +00:00
parent f392696d98
commit 121be3d9cf
2 changed files with 8 additions and 0 deletions

View File

@ -321,6 +321,10 @@ class MaxLengthQueue(queue):
class TwoWayDictionary(dict):
__slots__ = ()
def __init__(self, seq=(), **kwargs):
if hasattr(seq, 'iteritems'):
seq = seq.iteritems()
elif hasattr(seq, 'items'):
seq = seq.items()
for (key, value) in seq:
self[key] = value
self[value] = key

View File

@ -555,6 +555,10 @@ class TwoWayDictionaryTestCase(unittest.TestCase):
self.failUnless('foo' in d)
self.failUnless('bar' in d)
d = TwoWayDictionary({1: 2})
self.failUnless(1 in d)
self.failUnless(2 in d)
def testSetitem(self):
d = TwoWayDictionary()
d['foo'] = 'bar'