removing items from a dictionary ?

Alex Popescu nospam.themindstorm at gmail.com
Thu Jul 26 21:47:24 CEST 2007


Stef Mientki <S.Mientki-nospam at mailbox.kun.nl> wrote in
news:46A8EFF5.4060600 at mailbox.kun.nl: 

> hello,
> 
> I want to remove some items from a dictionary,
> so I would expect this should work:
> 
>    Nets = {}
>    ... fill the dictionary Nets
> 
>    for net in Nets:
>      if net.upper() in Eagle_Power_Nets :
>        del Nets [ net ]
> 
> 
> But it gives me
> Message     File Name     Line     Position
> Traceback               
>      ?     D:\data_to_test\JALsPy\Eagle_import.py     380     
> RuntimeError: dictionary changed size during iteration               
> 
>
> [snip...]
>
> 
> thanks,
> Stef Mientki

I think that you need to find a different iteration condition. Using 
for n in dict will iterate using an iterator which doesn't support 
"parallel" deletions.

bests,
./alex
--
.w( the_mindstorm )p.




More information about the Python-list mailing list