将dict转换为键列表?

tkb*_*kbx 0 python

有没有办法在Python中生成dict中的键列表?例如:

>>>someDict = {'One': 1, 'Two': 2, 'Three': 3}
>>>someList = someDict.keys()
>>>print someList
['One', 'Two', 'Three']
Run Code Online (Sandbox Code Playgroud)

Ade*_*taş 8

试试这个,

>>>someDict = {'One': 1, 'Two': 2, 'Three': 3}
>>>someList = list(someDict.keys())
>>>print(someList)
['One', 'Two', 'Three']
Run Code Online (Sandbox Code Playgroud)

  • @alexvassel取决于Python的版本 (3认同)