TypeError: 'dict

    xiaoxiao2025-04-23  16

    错误如下:

    TypeError: 'dict_keys' object does not support indexing

    这是由于python3改变了dict.keys,返回的是dict_keys对象,支持iterable 但不支持indexable,我们可以将其明确的转化成list: 解决方法:

    type(myTree) #dict #python2.x dict.keys() 返回list类型,可直接使用索引获取其元素 myTree.keys()[0] #python3.x dict.keys() 返回dict_keys类型,其性质类似集合(set)而不是列表(list),因此不能使用索引获取其元素 type(myTree.keys()) #dict_keys #python3.x解决办法 list(myTree.keys())[0]
    最新回复(0)