有一个字典,其中包含将要更改但出现错误的字典列表:
RuntimeError: dictionary changed size during iteration
这适用于python2,但不适用于python3。如何使其与python3兼容?
multi_van_data = {'Van1': [{'ClusterStops': [], 'OptimalStop': 'GSV07858'},
{'ClusterStops': [], 'OptimalStop': 'GSV07932'},
{'ClusterStops': [], 'OptimalStop': 'GSV07903'},
{'OptimalStop': 'GSV07892', 'ClusterStops': ['GSV07903']}]}
for k, v in multi_van_data.items():
for val in v:
val['ParentSequence'] = route.index(val['OptimalStop']) + 1
val['ParentServiceTime'] = 1
val['ParkstopTravelTime'] = 1
val['ApproxCompletionTime'] = []
cluster_stops = val['ClusterStops']
print cluster_stops
val.pop('ClusterStops')
要删除所有ClusterStops