mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 14:40:51 +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):
|
class TwoWayDictionary(dict):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __init__(self, seq=(), **kwargs):
|
def __init__(self, seq=(), **kwargs):
|
||||||
|
if hasattr(seq, 'iteritems'):
|
||||||
|
seq = seq.iteritems()
|
||||||
|
elif hasattr(seq, 'items'):
|
||||||
|
seq = seq.items()
|
||||||
for (key, value) in seq:
|
for (key, value) in seq:
|
||||||
self[key] = value
|
self[key] = value
|
||||||
self[value] = key
|
self[value] = key
|
||||||
|
@ -555,6 +555,10 @@ class TwoWayDictionaryTestCase(unittest.TestCase):
|
|||||||
self.failUnless('foo' in d)
|
self.failUnless('foo' in d)
|
||||||
self.failUnless('bar' in d)
|
self.failUnless('bar' in d)
|
||||||
|
|
||||||
|
d = TwoWayDictionary({1: 2})
|
||||||
|
self.failUnless(1 in d)
|
||||||
|
self.failUnless(2 in d)
|
||||||
|
|
||||||
def testSetitem(self):
|
def testSetitem(self):
|
||||||
d = TwoWayDictionary()
|
d = TwoWayDictionary()
|
||||||
d['foo'] = 'bar'
|
d['foo'] = 'bar'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user