我正在尝试通过索引访问dict_key的元素:
test = {'foo': 'bar', 'hello': 'world'}
keys = test.keys() # dict_keys object
keys.index(0)
AttributeError: 'dict_keys' object has no attribute 'index'
Run Code Online (Sandbox Code Playgroud)
我想得到foo.
同样的:
keys[0]
TypeError: 'dict_keys' object does not support indexing
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?