简体   繁体   English

如何在Python中向字典键添加多个值

[英]How to add multiple value to a dictionary key in Python

I am new to python. 我是python的新手。

list = {('9034','1234'):'BMW', '9996':'Chevy', '7206':'Ford'}
x = raw_input("Enter first 4 digit: ")
print (list[(x)])

How can i print BMW in both value '9034' and '1234' 如何打印值“ 9034”和“ 1234”的宝马

Just have two separate entries for it. 只需为其输入两个单独的条目。

list = {'9034': 'BMW', '1234': 'BMW', '9996': 'Chevy', '7206': 'Ford'}
x = raw_input("Enter first 4 digit: ")
print(list[x])

Also, please consider renaming list to something else since list is an object type and built-in name in Python. 另外,请考虑将列表重命名为其他名称,因为list是Python中的对象类型和内置名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM