Pythonify it

Add conditional execution, use ''.join, etc.