аватар question@mail.ru · 01.01.1970 03:00

How to remove a meaning from a dictionary during a cycle for

I somehow suddenly ran into such a problem. During the & nbsp; for I need to remove the records from it, but how can I tu out the error:

  Runtimeroror: Dictionary CHANGED SIZE DURING ITERANN  

I even tried to make a dictionary’s snapshot before iteration and Irte the double is removing from the original.

   & gt; & gt; & gt;  OT = { 12 :  'wqe' ,  13 :  'wqe' ,  14 :  'wqe' ,  15 :  '' '' '' ''}}   & gt; & gt;  OT1 = OT  & gt; & gt; & gt;   for  i  in  ot1:   ...   del  ot  ...  traceback (Most Recent Call Last):  File , Line  1 ,  in  & lt; module & gt; runtimeerror: dictionary Changed size duing iteration    

how to delete correctly? A little wrongly so correctly:

   & gt; & gt; & gt;  OT = { 12 :  'wqe' ,  13 :  'wqe' ,  14 :  'wqe' ,  15 :  '' '' '' ''}}   & gt; & gt;  OT1 = OT.copy ()   & gt; & gt; & gt;   for  i  in  ot1:   ...   del  ot  
аватар answer@mail.ru · 01.01.1970 03:00

You misunderstood the reason for what is happening.
You ask the question how to delete it correctly , but the right question
how to copy correctly? Dictionary.
Example

  x = [ '' 'wtf' ,  'justdoit' ] x1 = xx1 [ 0 ] =  'omg'    print  x & gt; & gt; [ 'omg' ,  'jostdoit' ]                                       

Latest

Similar