Skip to content
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

Open
pendave opened this issue Dec 22, 2017 · 3 comments
Open

跟老齐学Python 这个例子怎么运行不对? #127

pendave opened this issue Dec 22, 2017 · 3 comments

Comments

@pendave
Copy link

pendave commented Dec 22, 2017

35ed d60 l160vp9 3t 47e

g9 of5_ 61vmf a q5 hrkh

jh655ie j14 njoz 3lvlwy

reduce(lambda sum,(x,y): sum+x*y,zip(a,b),0)
我直接复制出来

@qiwsir
Copy link
Owner

qiwsir commented Dec 23, 2017 via email

@jintianming
Copy link

jintianming commented Jan 8, 2024 via email

@fish1968
Copy link

fish1968 commented Jan 8, 2024

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants