问题:python2.x 与python3.x之d.keys()返回类型的区别
TypeError: ‘dict_keys’ object does not support indexing
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]