[IronPython] Dict iteration inconsistency?
Simon Dahlbacka
simon.dahlbacka at gmail.com
Fri May 19 18:19:52 CEST 2006
They don't do the same thing..
fragment 1 iterates over a *copy* of the dictionarys keys, while fragment 2
iterates over the dictionary
On 5/19/06, J. de Hooge <info at geatec.com> wrote:
>
> LS
>
> Following code fragments seem to behave inconsistently
>
> [START OF CODE]
>
> # --- Fragment 1
> #
> # Accepted by CPython
> #
> # Accepted by IronPython1.0 B6
>
> dictionary = dict (zip (range (10), range (0, 100, 10)))
>
> print dictionary
>
> for key in dictionary.keys ():
> dictionary [key] = 100 * key
>
> print dictionary
>
> # --- Fragment 2: IronPython objects to the following, CPython thinks its
> OK
> #
> # Accepted by CPython
> #
> # Rejected by IronPython1.0 B6:
> # Traceback (most recent call last):
> # File C:\activ_dell\prog\qQuick\try\try.py, line 29, in
> Initialize
> # RuntimeError: dictionary changed size during iteration
>
> dictionary = dict (zip (range (10), range (0, 100, 10)))
>
> print dictionary
>
> for key in dictionary:
> dictionary [key] = 100 * key
>
> print dictionary
>
> # --- Shouldn't fragments 1 and 2 be both rejected or both accepted by
> IronPython?
>
> [END OF CODE]
>
>
> Kind regards,
> Jacques de Hooge
> info at geatec.com
>
>
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060519/6a74bea5/attachment.html>
More information about the Ironpython-users
mailing list