001、python报错如下:
>>> dict1 = {"aa":700, "bb":400, "cc":300, "dd":600} >>> dict1.values().index(300) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'dict_values' object has no attribute 'index'
002、报错原因,python3不支持 index用法
003、解决方法
>>> dict1 = {"aa":700, "bb":400, "cc":300, "dd":600} >>> dict1.values().index(300) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'dict_values' object has no attribute 'index' >>> list(dict1.values()).index(300) ## 增加list函数 2
标签:index,dict1,no,300,attribute,values From: https://www.cnblogs.com/liujiaxin2018/p/17451489.html