Change the code to let it more pythonic.