【发布时间】:2020-05-15 07:04:16
【问题描述】:
如何制作具有多个键和值的多维字典以及如何打印其键和值?
从这种格式:
main_dictionary= { Mainkey: {keyA: value
keyB: value
keyC: value
}}
我尝试这样做,但它给了我制造商的错误。这是我的代码
car_dict[manufacturer] [type]= [( sedan, hatchback, sports)]
这是我的错误:
File "E:/Programming Study/testupdate.py", line 19, in campany
car_dict[manufacturer] [type]= [( sedan, hatchback, sports)]
KeyError: 'Nissan'
我的打印代码是:
for manufacuted_by, type,sedan,hatchback, sports in cabuyao_dict[bgy]:
print("Manufacturer Name:", manufacuted_by)
print('-' * 120)
print("Car type:", type)
print("Sedan:", sedan)
print("Hatchback:", hatchback)
print("Sports:", sports)
谢谢!我是 Python 新手。
【问题讨论】:
-
如果您的代码引发“错误”,请包括实际错误和提供该错误的代码。我们无法确定您遇到的实际错误是什么,因此如果不猜测问题实际是什么,我们就无法真正帮助您。
标签: python-3.x dictionary multidimensional-array printing key