back soft

مطالب مرتبط با «python iterate over set» در back soft | نویسنده: استخدام کار

python iterate over dictionary emptys it

Vote count: 0 I have some code I'm analyzing. But I've found that iterating over a dictionary empties it. I've fixed the problem by by making a deepcopy of the dictionary and iterating over that in some code that displays the values, then later use the original dictionary to iterate over that to assign values to a 2D array. Why does iterating over the original dictionary to display it empty it, so that later use of the dictionary is unusable since it is now empty? Any replies welcome. import copy # This line fixed the problem trans = copy.deepcopy(transitions) print ("nTransistions = ") # Original line was: # for state, next_states in transitions.items(): # Which empties the dictionary, so n...

ادامه مطلب

برچسب‌های مرتبط

python iterate over dictionary | python iterate over list | python iterate over array | python iterate over files in directory | python iterate over two lists | python iterate over set | python iterate over string | python iterate over list with index | python iterate over lines in file | python iterate over directory