简体   繁体   English

字典打印中的Python字典

[英]Python dictionary in a dictionary printing

I'm trying to print the value of 'a' in couples in random_dict but the error "TypeError: string indices must be integers" is coming up,我试图在 random_dict 中打印成对的 'a' 的值,但出现错误“TypeError:字符串索引必须是整数”,

Code:代码:

coupleascore = 20
couplebscore = 23
couplecscore = 25

judge1scores = [1, 3, 5]
judge2scores = [5, 2, 10]
judge3scores = [7, 5, 9]

random_dic = {'couples': {'a': coupleascore, 'b': couplebscore, 'c': couplecscore} ,'judges': {'1': judge1scores, '2': judge2scores, '3': judge3scores}}

print(key(['random_dic'['couples'['a']]]))

Edit your last line to this:将最后一行编辑为:

print(random_dic['couples']['a'])

https://docs.python.org/3/tutorial/datastructures.html#dictionaries for more on the dictionary data structure https://docs.python.org/3/tutorial/datastructures.html#dictionaries有关字典数据结构的更多信息

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

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