003Square(n)Sum(8kyu)from codewars
Square(n)Sum
Complete the square sum function so that it squares each number passed into it and then sums the results together.
完成平方和函数,对每个传入其中的数字平方并相加。
def square_sum(numbers):
sums=0
for i in numbers:
sums+=i*i
return sums
def square_sum(numbers):
result=[]
for sqr in numbers:
result.append(sqr**2)
return sum(result)
def square_sum(numbers):
return sum([x**2 for x in numbers])
def square_sum(numbers):
return sum(x**2 for x in numbers)
import numpy
def square_sum(numbers):
return sum(numpy.array(numbers)**2)
def square_sum(numbers):
return sum(map(lambda x:x**2,numbers))
sum(iterable[,start])
对序列中的每个元素求和
返回数值
- iterable--列表、元组、集合
- start--指定相加的参数
map(function,iterable,...)
iterable中的每个元素调用function
返回iterable
- function--函数
- iterable--一个或多个序列