python字典问题

hamlettxt = gettext()
words = hamlettxt.split()
counts = {}
for word in words:
  counts[word] = count.get(word,0) + 1
items = list(count.items())
items.sort(key=lambda x:x[1], reverse=True)
for i in range(10):
  word,count = item[i]
  print("{0:<10}{1:>5}".format(word,count))

这里的items = list(count.items()),d.items()本身不就是返回一个列表吗,为什么还要添加一个list()使其列表化?如果不是的话,那d.items()返回的是什么东西呢?

你可以输出一下看看
它的返回值是:可遍历的(键, 值) 元组数组

img

dict = {"name": "xiaoming"}
for i , k in duct.items():
print(i, k)

name xiaoming