python中的解析器dict
我有一句话:python中的解析器dict,python,dictionary,Python,Dictionary,我有一句话: test = {0: {'nom': 'toto', 'id':1}, 2: {'nom': 'tutu', 'id': 2}} 我想打印一个结果,如 toto tutu 我试着 但不起作用 谢谢,因为你的第一个字典的钥匙是数字。不是“nom” for k in test: print test[k]['nom'] 这应该适用于Python3和Python2。使用下面的内容仅适用于2 for nom in test: print test[n
test = {0: {'nom': 'toto', 'id':1}, 2: {'nom': 'tutu', 'id': 2}}
我想打印一个结果,如
toto
tutu
我试着
但不起作用
谢谢,因为你的第一个字典的钥匙是数字。不是“nom”
for k in test:
print test[k]['nom']
这应该适用于Python3和Python2。使用下面的内容仅适用于2
for nom in test:
print test[nom]['nom']
你是说
values()
?不,@karthikr,它的.keys()
,其中test.keys()
会将所有一级键作为一个列表提供给你如果你真的是指keys
,那么最好完全忽略它。投票否决这个问题的人是谁?你看不出他是新来的吗。smh@YankiTwizzy尽管人们能够理解“但不工作”是什么意思,但仅仅说“它不工作”而不解释这意味着什么(编译错误?输出不是你期望的?计算机爆炸了?)和当前发生的事情的输出,仍然被认为是不好的形式。我没有投反对票,但我猜这就是人们投反对票的原因。
for k in test:
print test[k]['nom']
for nom in test:
print (test[nom]['nom'])
for nom in test:
print test[nom]['nom']