1. 报错:python:TypeError: 'dict_keys' object does not support indexing
2. 解决:
https://blog.csdn.net/a070220106/article/details/9089379 TypeError: 'dict_keys' object does not support indexing
https://blog.csdn.net/shuiyixin/article/details/87910896 Python报错:TypeError: 'dict_keys' object does not support indexing(机器学习实战treePlotter代码)解决方案
由于python3改变了dict.keys,返回的是dict_keys对象,支持iterable 但不支持indexable,我们可以将其明确的转化成list:
将以下代码:
firstStr = inputTree.keys()[0]
改成:
firstStr = list(inputTree.keys())[0]
即可。