【发布时间】:2010-12-29 00:32:21
【问题描述】:
我有以下代码,它只是打印字典中的键/值对(这些对按键排序):
for word, count in sorted(count_words(filename).items()):
print word, count
但是,调用 iteritems() 而不是 items() 会产生相同的输出
for word, count in sorted(count_words(filename).iteritems()):
print word, count
现在,在这种情况下我应该选择哪一个?我咨询了Python tutorial,但它并没有真正回答我的问题。
【问题讨论】:
标签: python