Nested List Hackerrank Solution Python