Skip to content

Instantly share code, notes, and snippets.

@kanglicheng
Created July 24, 2017 20:25
Show Gist options
  • Save kanglicheng/065ef3f7e1729b591b45c946e5c9fbc2 to your computer and use it in GitHub Desktop.
Save kanglicheng/065ef3f7e1729b591b45c946e5c9fbc2 to your computer and use it in GitHub Desktop.
def convertFracts(lst):
n= len(lst)
ans =[[0]*2 for _ in range(n)]
for i in range(n):
ans[i][0]=lst[i][0]/gcd(lst[i][0], lst[i][1])
ans[i][1] = lst[i][1]/gcd(lst[i][0], lst[i][1])
return ans
def gcd(a, b):
"""Return greatest common divisor using Euclid's Algorithm."""
while b:
a, b = b, a % b
return a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment