Message87729
I'm not sure if this is a documentation bug or a behaviour bug, or
possibly both.
The documentation warns about adding or deleting items from a dict
while iterating over it:
"Using iteritems() while adding or deleting entries in the dictionary
will raise a RuntimeError."
http://docs.python.org/library/stdtypes.html#dict.iteritems
Same for other dict iterators.
However, you can add and delete items, so long as the overall size of
the dict doesn't change. Consequently, some modifications to the dict
aren't caught, leading to various misbehaviour in (at least) Python
2.5 and 2.6.
Some dicts appear to "run too long":
>>> d = dict(x=3, y=4) # Two items
>>> it = d.iteritems()
>>> it.next() # One
('y', 4)
>>> del d['y']
>>> d['z'] = 5
>>> it.next() # Two
('x', 3)
>>> it.next() # Three
('z', 5)
While others run too short:
>>> d = {-1: 'aa', -2: 'bb'} # Two items
>>> it = d.iteritems()
>>> it.next() # One
(-2, 'bb')
>>> del d[-1]
>>> d[0] = 'cc'
>>> it.next()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration |
|
Date |
User |
Action |
Args |
2009-05-14 05:44:07 | steven.daprano | set | recipients:
+ steven.daprano, georg.brandl |
2009-05-14 05:44:04 | steven.daprano | set | messageid: <1242279843.94.0.529178267811.issue6017@psf.upfronthosting.co.za> |
2009-05-14 05:43:56 | steven.daprano | link | issue6017 messages |
2009-05-14 05:43:46 | steven.daprano | create | |
|