A source converter made for fun based off this question on StackOverflow
Quick examples to demonstrate working of this project :
Before conversion:
def fib(n):
if n <= 1:
return n
return fib(n - 1) + fib(n - 2)
print(fib(5))
After conversion:
from operator import sub, add, le
def fib(n):
if le(n, 1):
return n
return add(fib(sub(n, 1)), fib(sub(n, 2)))
print(fib(5))
Before conversion:
def foo(x, y, z):
z += 1
y = x >> y
x @= y
x, y = y, x
return (x + y ^ z) or y // x
After conversion:
from operator import xor, imatmul, iadd, rshift, add, floordiv
def foo(x, y, z):
z = iadd(z, 1)
y = rshift(x, y)
x = imatmul(x, y)
(x, y) = (y, x)
return xor(add(x, y), z) or floordiv(y, x)
The following conversions are implemented :