Find sum of square of list in python by R4R Team

Example-

list is [1,2,3,4]
then sum of square is 30


program-

#import the functools module
import functools

l=[1,2,3,4,5]
print("List is ",l)

l=list(map(lambda x:x**2,l))
print("List become",l)

sum=functools.reduce(lambda x,y:x+y,l)
print("Sum of square is :",sum)


output-

List is [1,2,3,4,5]
List become [1,4,9,16,25]
Sum of square is : 55


-In this program, we take an input of the list items, then using lambda function and map() function we find the square of the list.
-Then using reduce() and lambda function we find the sum of items in the list.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!