How to access specific element of dictionary of tuples

陌路散爱 提交于 2019-12-05 21:35:46
for item in dict:
    print dict[item][2]

Also, you should not name anything after a built-in, so name your dictionary 'd' or something other than 'dict'

for item in dict: does the same thing as for item in dict.keys().

Alternatively, you can do:

for item in dict.values():
    print item[2]

Your code is close, but you must key into the dictionary and THEN print the value in index 2.

You are printing parts of the Keys. You want to print parts of the Values associated with those Keys:

for item in dict:
   print dict[item][2]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!