Python Nested List Hackerrank Solution