def combine_guests(guests1, guests2):
# Combine both dictionaries into one, with each key listed
# only once, and the value from guests1 taking precedence
Rorys_guests = { "Adam":2, "Brenda":3, "David":1, "Jose":3, "Charlotte":2, "Terry":1, "Robert":4}
Taylors_guests = { "David":4, "Nancy":1, "Robert":2, "Adam":1, "Samantha":3, "Chris":5}
print(combine_guests(Rorys_guests, Taylors_guests))
想要这个输出吗
{"Adam": [2, 1], "Branda": 3, "David": [1, 4] ...}
对于来自guests1的值,即Rorys_guests dict将优先。例如,对于Adam,键值为[2,1]
这可能会有帮助。这将优先于
Rorys_guests
,并且不包括来自Taylors_guests
的值(如果两者都具有该值)Python 3.5或更高版本
相关问题 更多 >
编程相关推荐