标签:obb collect chain job 内存 col 加载 res bsp
旧方法
a = {‘name‘:‘tom‘,‘age‘:18}
aa = {‘job‘:‘student‘,‘hobby‘:‘eat‘}
a.update(aa)
print(a)
>>> {‘name‘: ‘tom‘, ‘age‘: 18, ‘job‘: ‘student‘, ‘hobby‘: ‘eat‘}
新方法
from collections import ChainMap
a = {‘name‘:‘tom‘,‘age‘:18}
aa = {‘job‘:‘student‘,‘hobby‘:‘eat‘}
result = ChainMap(a,aa)
print(result)
>>> ChainMap({‘name‘: ‘tom‘, ‘age‘: 18}, {‘job‘: ‘student‘, ‘hobby‘: ‘eat‘})
a.pop(‘name‘)
result = ChainMap(a,aa)
print(result)
>>> ChainMap({‘age‘: 18}, {‘job‘: ‘student‘, ‘hobby‘: ‘eat‘})
print(result[‘hobby‘])
>>> eat
print(a)
>>> {‘age‘: 18}
总结
新方法类似于列表生成式,不会将所有数据都加载出来,耗费空间,而是要哪个获取哪个
标签:obb collect chain job 内存 col 加载 res bsp
原文地址:https://www.cnblogs.com/zhang-dan/p/11005390.html