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