Make code more Pythonic