We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Reduce Function
Reduce Function
Sort by
recency
|
213 Discussions
|
Please Login in order to post a comment
The simple line needed to complete the skeleton function is…
Let Python do the work. There's no need to construct a
lambda
.There are several solutions posted in this forum that do the reduction using the
Fraction
constructor to do the multiplication. It works, but it requires a little bit of special knowledge to set up the calculation and to return the result. The reduction must start with1
, to get the reciprocal of the first fraction. After the reduction, the reciprocal is returned by giving the numerator and denominator in the opposite order. Although the solution is clever and somewhat smaller, i don't recommend it, because the way it works isn't obvious to most people and is therefore difficult to maintainHere is HackerRank Reduce Function in Python solution - https://programmingoneonone.com/hackerrank-reduce-function-solution-in-python.html