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,
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.