【Kata Daily 190920】Square(n) Sum(平方加总)

题目:

Complete the square sum function so that it squares each number passed into it and then sums the results together.

For example, for [1, 2, 2] it should return 9 because 1^2 + 2^2 + 2^2 = 9.

 

解题方法:(再想想可能就出来了)

def square_sum(numbers):
    return sum(map(lambda x: x**2,numbers))

 

还有其他的办法:

def square_sum(numbers):
    return sum(x**2 for x in numbers)

 

posted @ 2019-09-20 11:04  bcaixl  阅读(296)  评论(0编辑  收藏  举报