[Python] Simple Parsing - with example
html5\n<b>Time Complexity: O(n + log(N&middot;D))</b> where n = expression.length and (N, D) are the unreduced numerator and common denominator &becaus; while-l
```html5\n<b>Time Complexity: O(n + log(N&middot;D))</b> where n = expression.length and (N, D) are the unreduced numerator and common denominator &becaus; while-loop and gcd\n<b>Space Complexity: O(n)</b> &becaus; num and den both scale with n and &becaus; when the first fraction is positive: expression = \'+\' + expression\n```\n\nWe will use the example `"-3/1+2/3-3/2+4/7+5/5"` while walking through the approach.\nSteps are also annotated within the code.\n\n**Approach:**\n\nFirst use a while-loop iterate over `expression` once.\nEach loop, we will extract one fraction from the expression:\n1. `expression[i]` will tell us if the numerator is positve or negative\n2. The following characters that are digits will make up the numerator.\n3. Skip the next character, it will always be `\'/\'`.\n4. The following characters that are digits will make up the denominator.\n\nAfter which the cycle either ends because we reached the end of `expression`\nor the cycle repeats starting with a new `+` or `-` denoting the sign of the next fraction.\n\nStore all of the numerators in a list `num` and all of the denominators in a separate list `den`.\nAn easy way to find a common divisor is to just multiply all of the denominators together.\nI.e: `den = [1, 3, 2, 7, 5] -> denominator = 1*3*2*7*5 = 210`\n\nThen multiply each numerator and denominator by `210 / den` so that it can be represented as `new_numerator / 210`.\n```html5\nnum = [-3, 2, -3, 4, 5] -> num = [-3/1, 2/3, -3/2, 4/7, 5/5] * 210 -> num = [-630, 140, -315, 120, 210]\nden = [ 1, 3,  2, 7, 5] -> den = [ 1/1, 3/3,  2/2, 7/7, 5/5] * 210 -> den = [ 210, 210,  210, 210, 210]\n```\n\nNow our numerators and denominators look like this:\n```html5\nnum = [-630, 140, -315, 120, 210]\nden = [ 210, 210,  210, 210, 210]\n```\n\nSince all of the fraction share the same denominator, we can combine them through addition:\n`numerator = -475`\n`denominator = 210`\n\nFinally, all that is left to do is to reduce the fraction.\nThis can be done by dividing the numerator and denominator by their greatest common divisor.\n`gcd(-475, 210) = 5   ->  numerator = -475 / 5 = -95 -> denominator = 210 / 5 = 42`\n`gcd(-95, 42) = 1`\n\nHence, the final answer is `"numerator / denominator" = "-95/42"`.\n\n```python\nclass Solution:\n    def fractionAddition(self, exp: str) -> str:\n        \n        if not exp:\n            return "0/1"\n        \n        if exp[0] != \'-\':\n            exp = \'+\' + exp\n        \n        # Parse the expression to get the numerator and denominator of each fraction\n        num = []\n        den = []\n        pos = True\n        i = 0\n        while i < len(exp):\n            # Check sign\n            pos = True if exp[i] == \'+\' else False\n            \n            # Get numerator\n            i += 1\n            n = 0\n            while exp[i].isdigit():\n                n = n*10 + int(exp[i])\n                i += 1\n            num.append(n if pos else -n)\n            \n            # Get denominator\n            i += 1\n            d = 0\n            while i < len(exp) and exp[i].isdigit():\n                d = d*10 + int(exp[i])\n                i += 1\n            den.append(d)\n        \n        # Multiply the numerator of all fractions so that they have the same denominator\n        denominator = functools.reduce(lambda x, y: x*y, den)\n        for i,(n,d) in enumerate(zip(num, den)):\n            num[i] = n * denominator // d\n        \n        # Sum up all of the numerator values\n        numerator = sum(num)\n        \n        # Divide numerator and denominator by the greatest common divisor (gcd)\n        g = math.gcd(numerator, denominator)\n        numerator = numerator // g\n        denominator = denominator // g\n        \n        return f"{numerator}/{denominator}"\n```
['Python', 'Python3']