python複数の辞書を結合して1つの辞書を構成
2107 ワード
from collections import ChainMap
import collections
value = ChainMap()
for list_num in range(1,13):
li_list = list_num + 1
value["li_name%s"%(list_num)] = li_list
value=value.new_child()#
value=value.parents#
print(value)#
print(dict(value))#
+++++++++++++++++++++++++++++++++++++++++++++++
C:\python3.7\python.exe D:/Python-Test/StuProject/StuApp/tests.py
ChainMap({'li_name1': 2, 'li_name2': 3, 'li_name3': 4, 'li_name4': 5, 'li_name5': 6, 'li_name6': 7, 'li_name7': 8, 'li_name8': 9, 'li_name9': 10, 'li_name10': 11, 'li_name11': 12, 'li_name12': 13})
{'li_name1': 2, 'li_name4': 5, 'li_name11': 12, 'li_name2': 3, 'li_name12': 13, 'li_name7': 8, 'li_name8': 9, 'li_name5': 6, 'li_name10': 11, 'li_name3': 4, 'li_name9': 10, 'li_name6': 7}
転載先:https://www.cnblogs.com/acer-haitao/p/8277956.html