More Ruby to Python conversion