gpt4 book ai didi

python lambda函数语法错误

转载 作者:太空宇宙 更新时间:2023-11-04 00:18:14 25 4
gpt4 key购买 nike

def get_cluster_rows():
for path, rows in itertools.groupby(get_word_rows(), key=lambda x: x[0]):
wordcounts = [(w,c) for _,w,c in rows]
wordcounts.sort(key=lambda (w,c): -c)

yield path, len(wordcounts), wordcounts[:50], wordcounts

语法错误:语法无效:

wordcounts.sort(key=lambda (w,c): -c)
^

如何用 (w,c) 编写 lambda 函数?

最佳答案

你应该删除括号:

wordcounts.sort(key=lambda w, c: -c)

关于python lambda函数语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50129655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com