Python中字典的items函数的返回值存疑

先说起因,我在学习MOOC上北理嵩天的Python课程,在编写一段代码时发现了这样的问题:

counts = {}
for word in words:
    if len(word)==1:
        continue
    elif word == "诸葛亮" or word == "孔明曰":
        rword = "孔明"
    elif word == "孟德" or word == "丞相":
        rword = "曹操"
    elif word == "玄德" or word == "玄德曰":
        rword = "刘备"
    elif word == "关公" or word == "云长":
        rword = "关羽"
    else:
        rword = word
    counts[rword] = counts.get(rword,0) + 1
for word in excludes:
    del counts[word]
items = list(counts.items())

最后一行便是问题所在既然counts.items()函数的返回值是一个列表
那为何还要用list()将counts.items()的返回值转化为列表类型呢?

我自己尝试着打印了一下counts.items()的结果,从形式上看,返回值的确是一个元组类型

x = {'title':'python web site','name':'123'}
print(x.items())

运行结果:dict_items([('title', 'python web site'), ('name', '123')]) #最外层是括号,这不应该是元组类型吗?
但我在网络上铺天盖地地搜了很多关于items()函数的信息,都说items()函数的返回值是一个列表,这属实给我带来了很大的困惑。
希望大家能够帮我解答!

Python 2的items()函数的返回值是一个列表, 但在Python 3中为了优化性能, 改成了一个可迭代对象, 所以需要用list()转换。

img


img


Python 版本不同, 特性就不同。
如果有帮助, 点个「采纳」谢谢。

他返回的是一个迭代器,不能像列表一样直接访问元素,但是可以遍历