Make the code more pythonic