【发布时间】:2012-06-23 19:38:14
【问题描述】:
我正在寻找最好的 Pythonic 方法来做到这一点。
嵌套字典看起来像这样(主脚本):
my_dict = { test: {
test_a: 'true',
test_b: 'true
}
我正在导入一个具有返回数值的函数的模块。
我正在寻找一种从模块返回的字典中追加到 my_dict 字典的方法。
即模块中的函数:
def testResults1():
results = 3129282
return results
def testResults2():
results = 33920230
return results
def combineResults():
Would like to combine results, and return a dictionary. Dictionary returned is:
# Looking for best way to do this.
test_results = { 'testresults1': 3129282,
'testresults2': 33920230
}
然后我想将 test_results 字典附加到 my_dict。 也在寻找最好的方法来做到这一点。
提前谢谢你!
【问题讨论】:
-
为什么嵌套很重要?你希望你的新字典插入到
my_dict的“顶层”还是test下? -
my_dict 的最终预期值是多少?
标签: dictionary nested python