python dictionary type index error problem

Error statement:

id_name_dic.keys()[2]

mistake:

'dict_keys' object does not support indexing

This is how python2 is written . In python2.x, dict.keys() returns a list. In python3.x, dict.keys() returns a dict_keys object, which behaves more like a set than a list. So indexing is not supported.

   解决方案:list(dict.keys())[index]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325386203&siteId=291194637