more pythonic solution