Flatten List Python Using Nested If Statements