列表元素的平方和

Nat*_*ate -11 python iteration computer-science list

写一个函数sum_of_squares(xs)来计算列表xs中数字的平方和.例如,sum_of_squares([2, 3, 4])应返回4 + 9 + 16,即29:

ins*_*get 10

这是一个不错的单线

sum_of_squares = lambda L : sum(map(lambda iGotThisFromStackOverflow:iGotThisFromStackOverflow**2, L))
Run Code Online (Sandbox Code Playgroud)

  • 厚脸皮;)我希望他们提交这个作为他们的任务答案! (5认同)