better pythonic code