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