durusmail: durus-users: del btree[key] ?
del btree[key] ?
2005-07-11
del btree[key] ?
Mario Ruggier
2005-07-11
Hi,

deleting items in a btree behaves surprisingly, when the key is complex.
Here is a little sequence of commands that shows what I mean. Why isn't
that one remaining item not deleted?

$ python
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from durus.btree import BTree
>>> b = BTree()
>>> b.add(1234, BTree)
>>> b.items()
[(1234, )]
>>> class Test(object): pass
....
>>> b[(Test(),Test(),'ssss',Test())] = Test()
>>> b.items()
[(1234, ), ((<__main__.Test object at 0xc4b10>,
<__main__.Test object at 0xc4ad0>, 'ssss', <__main__.Test object at
0xc4a90>), <__main__.Test object at 0xc4ff0>)]
>>> for key in b: print key
....
1234
(<__main__.Test object at 0xc4b10>, <__main__.Test object at 0xc4ad0>,
'ssss', <__main__.Test object at 0xc4a90>)
>>> for key in b: del b[key]
....
>>> b.items()
[((<__main__.Test object at 0xc4b10>, <__main__.Test object at 0xc4ad0>,
'ssss', <__main__.Test object at 0xc4a90>), <__main__.Test object at
0xc4ff0>)]
>>>
>>>


mario

reply