def flatten(nested): for sublist in nested: for element in sublist: yield elementnested = [[1, 2], [3, 4], [5]]for num in flatten(nested): print numprint list(flatten(nested))