RuntimeError:字典在使用Python3的迭代过程中更改了大小?

时间:2019-01-03 10:25:21

标签: python python-3.x dictionary

有一个字典,其中包含将要更改但出现错误的字典列表:

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

0 个答案:

没有答案