more pythonic code to @nycz