匿名函數問題?
print(sorted([1,3,9,5,0],lambda x,y:-cmp(x,y)))
運行后顯示:
?sorted([1,3,9,5,0],lambda x,y:-cmp(x,y))
TypeError: must use keyword argument for key function
我在python3.5環(huán)境中運行,求解?
print(sorted([1,3,9,5,0],lambda x,y:-cmp(x,y)))
運行后顯示:
?sorted([1,3,9,5,0],lambda x,y:-cmp(x,y))
TypeError: must use keyword argument for key function
我在python3.5環(huán)境中運行,求解?
2016-06-04
舉報
2016-06-04
不然你試試在lambda前加個key=,我在http://stackoverflow.com/questions/23082372/sorting-a-list-with-lambda-with-a-variable-number-of-arguments看到個感覺和你很像的問題,剛學,共勉