【发布时间】:2021-11-06 05:57:19
【问题描述】:
我正在遍历字典中的步骤,并为每个步骤提取一个联系电话号码和一个 ID,并将这些作为键/值对放入一个新的字典中:contacts
contacts = {}
for execution_step in execution_steps["steps"]:
main_execution_context = get_execution_context(execution_step["url"])
contact_phone = main_execution_context["contact"]
id = main_execution_context["id"]
contacts[contact_phone] = id
如果存在contact_phone 的重复项,即密钥已经存在,是否可以将值对 (id) 附加到现有值上,从而创建与同一电话号码关联的 id 列表?
【问题讨论】:
标签: python dictionary key-value