R to Python Translation