In Python 2.7 , I could get dictionary keys , values , or items as a list:
(在Python 2.7中 ,我可以将字典键 , 值或项作为列表获取:)
>>> newdict = {1:0, 2:0, 3:0}
>>> newdict.keys()
[1, 2, 3]
Now, in Python >= 3.3 , I get something like this:
(现在,在Python> = 3.3中 ,我得到如下信息:)
>>> newdict.keys()
dict_keys([1, 2, 3])
So, I have to do this to get a list:
(因此,我必须这样做以获得列表:)
newlist = list()
for i in newdict.keys():
newlist.append(i)
I'm wondering, is there a better way to return a list in Python 3 ?
(我想知道,是否有更好的方法在Python 3中返回列表?)
ask by translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…