gray concrete stairs inside building
Photo by Gayatri Malhotra on Unsplash

If you happen to learn programming from a textbook, you may have seen an example where you are told to exercise writing a quick program that allows you to find the product of elements, for example:

If you however want to find the product of all elements in a list, you need to iterate through that list in the following way:

That’s the way you also used when you were in a Math exam in high school.

There is however a quicker way that you can do that. This relies on using method prod from the math module:

That’s actually quite neat, right? 

It’s something that I also learned only a couple of days ago, so I hope you find it useful.