mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Made the constructor take dictionaries.
This commit is contained in:
parent
f392696d98
commit
121be3d9cf
@ -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
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user