+4 votes
in Programming Languages by (40.5k points)

The following Python code is throwing error: "TypeError: <lambda>() missing 1 required positional argument: 'b'" . I am using Python3 for my code. How can I fix the error?

return max(map(lambda a, b: (0 if a == 0 else float(b) / (a + k)), counts))

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

Since you are using  Python 3, you can change your code to the following code and it should fix the error. In Python 2, use of tuple was allowed, but tuple will not work in Python3.

return max(map(lambda a: (0 if a[0] == 0 else float(a[1]) / (a[0] + k)), counts))


...