2
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

SyntaxError: invalid syntax:

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

how to write lambda function with (w,c)?

1
  • 2
    Remove brackets Commented May 2, 2018 at 7:57

2 Answers 2

2

You should remove brackets:

wordcounts.sort(key=lambda w, c: -c)
Sign up to request clarification or add additional context in comments.

Comments

1

Simply list your comma separated parameters without any brackets like:

f = lambda x,y: x+y
f(2,3)
5

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.