2-4 中使用Python3 直接使用sorted+lambda进行 排序报错,什么原因
来源:

易水寒楠
2017-01-10
>>> d={x:randint(60,100) for x in 'xyzabc'}
>>> d
{'x': 64, 'b': 70, 'c': 87, 'y': 93, 'z': 89, 'a': 78}
>>> d.items()
dict_items([('x', 64), ('b', 70), ('c', 87), ('y', 93), ('z', 89), ('a', 78)]
)
>>> sorted(d.items().key=lambda x:x[1])
File "<stdin>", line 1
SyntaxError: keyword can't be an expression
写回答
1回答
-
程序员硕
2017-01-10
python3中d.items返回的不是list, 是可迭代对象.需要list(d.items())构造列表.
00
相似问题