Created
April 30, 2015 04:50
-
-
Save sincerefly/e18d5e300b5d8a1fbdf4 to your computer and use it in GitHub Desktop.
返回列表内数值的平方和
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 方法1 | |
def square_sum(numbers): | |
return sum(x**2 for x in numbers) | |
# 方法2 | |
def square_sum2(numbers): | |
return sum(map(lambda x: x**2, numbers)) | |
# 方法3 | |
def square_sum(numbers): | |
res = 0 | |
for num in numbers: | |
res = res + num*num | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment