HackerRank Python - Reduce Function




The reduce() function applies a function of two arguments cumulatively on a list of objects in succession from left to right to reduce it to one value. Say you have a list, say [1,2,3] and you have to find its sum.



  1. from fractions import Fraction
  2. from functools import reduce
  3. def product(fracs):
  4. t = Fraction(reduce(lambda x, y: x * y, fracs))
  5. return t.numerator, t.denominator
  6. if __name__ == '__main__':
  7. fracs = []
  8. for _ in range(int(input())):
  9. fracs.append(Fraction(*map(int, input().split())))
  10. result = product(fracs)
  11. print(*result)
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube