Do you know the magic of REDUCE in Python?

Before jumping on to what is reduce, let’s have a quick look at the lines below:

sum = 0for n in [1,2,3]:sum = sum + nprint(sum)

You got it right. Here we are taking a collection having three numbers and summing them up.

As such, there is nothing wrong with this code but, of course there is a big room for optimization with respect to the number of lines of code we have written, just go get summation.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store