Some pythonic way to achieve this?