Hackerrank Python Nested List Solution