Convert pseudo-python to python