import numpy as np
from collections import OrderedDict
Dict = OrderedDict()
a =[2,86,94,2,75,1,23,89]
for i in range(len(a)):
Dict[i] = a[i]
print(Dict)
print(len(Dict))
L = [i for i in range(len(Dict))]
for i in L:
if i == 7:
L.append(len(L))
Dict[len(Dict)] = len(Dict)
elif i == 8:
L.append(len(L))
Dict[len(Dict)] = len(Dict)
elif i == 9:
L.append(len(L))
Dict[len(Dict)] = len(Dict)
print(Dict)
使用一个List进行计数迭代。List可以不断加大。也可以随着字典删除修改List从而达到遍历动态字典的目的。