diff --git a/src/structures.py b/src/structures.py index dd0e622a9..8c6f05c98 100644 --- a/src/structures.py +++ b/src/structures.py @@ -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 diff --git a/test/test_structures.py b/test/test_structures.py index 497867f59..ad92ee81d 100644 --- a/test/test_structures.py +++ b/test/test_structures.py @@ -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'