Flatten List Python Using Nested Loops