deftriangles(n): result = [1, 1] for i inrange(1, n + 1): if i == 1: yield [1] elif i == 2: yield [1, 1] else: next_result = [result[0]] for j inrange(1, len(result)): next_result.append(result[j-1] + result[j]) next_result.append(result[-1]) result = next_result yield result
defprint_triangels(n): for i in triangles(n): print(i)