Hacker Rank Nested List Solution Python