有没有办法在 python 中打印匿名字典的键和值。
for key in {'one':1, 'two':2, 'three':3}:
print key, ":", #value
最佳答案
for key, value in {'one':1, 'two':2, 'three':3}.iteritems():
print key, ":", value
默认情况下,遍历它会返回它的键。 .iteritems() 返回(键,值)的二元组。
关于python - 在 python 中循环一个未命名的字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10102016/