【发布时间】:2021-05-11 18:19:31
【问题描述】:
如果我有两个字典,并且我想根据外部输入将其分配给另一个变量,是否有更 Pythonic 的方式来做呢?
dict_one = {"id": 1, "content": "content of the first dict"}
dict_two = {"id": 2, "content": "content of the second dict"}
dict_three = {"id": 3, "content": "content of the third dict"}
#insert many more dicts....
outside_input = 1
if outside_input == 1:
result = dict_one
elif outside_input == 3:
result = dict_three
【问题讨论】:
标签: python dictionary variable-assignment