Modify the code to be a bit more pythonic