I have a list of fractions that I need to transform.
from fractions import Fraction
fractions_list=[Fraction(3,14),Fraction(1,7),Fraction(9,14)]
The output should be a list with the numerators for each fraction, followed by the least common denominator for all of them. For above example the result (3/14, 2/14, 9/14) would be represented as follows
[3,2,9,14]
Is there an elegant solution for this? All I can think of involves a lot of intermediate lists to store some variables, and scales horribly.
numpy.lcm
would work. – Hodgemath.lcm(*integers)
for this in Python 3.9+ (Oct 2020). – Weakly