15年16年接触python时候,还不知道这个函数,只知道dict的无序,造成了一些麻烦
今天view 代码,发现了 OrderedDict()
在python2.7中比较吃内存
pop(获取指定key的value,并在字典中删除)
from collections import OrderedDict
print("Before deleting:
")
od = OrderedDict()
od['a'] = 1
od['b'] = 2
od['c'] = 3
od['d'] = 4
for key, value in od.items():
print(key, value)
print("
After deleting:
")
od.pop('c')
for key, value in od.items():
print(key, value)
print("
After re-inserting:
")
od['c'] = 3
for key, value in od.items():
print(key, value)