Skip to content

Instantly share code, notes, and snippets.

@sincerefly
Created April 30, 2015 04:50
Show Gist options
  • Save sincerefly/e18d5e300b5d8a1fbdf4 to your computer and use it in GitHub Desktop.
Save sincerefly/e18d5e300b5d8a1fbdf4 to your computer and use it in GitHub Desktop.
返回列表内数值的平方和
# 方法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