-
Notifications
You must be signed in to change notification settings - Fork 841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
跟老齐学Python 这个例子怎么运行不对? #127
Comments
你的邮件收到,谢谢!
|
https://stackoverflow.com/questions/11328312/python-lambda-does-not-accept-tuple-argument 参考这里,使用 tuple 作为 lambda 参数的特性在 python3 中被取消了,可以改为 reduce(add,map(lambda x: x[0]*x[1], zip(a,b)))
reduce(lambda x,y: x+y, map(lambda x,y: x*y, a, b))
reduce(lambda x,y: x+y[0]*y[1], zip(a,b),0) # 0 must be provided here, otherwise the first tuple of zip(a,b) would be the initial value, and error happens due to tuple type added with int type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reduce(lambda sum,(x,y): sum+x*y,zip(a,b),0)
我直接复制出来
The text was updated successfully, but these errors were encountered: