Замена цикла на генератор:
n = 4
a = [0] * n
a = [[2] * i + [1] + [0] * (n - i - 1) for i in range(n)]
for row in a:
print(' '.join([str(elem) for elem in row]))
http://pythontutor.ru/lessons/2d_arrays/
>>> n = 4
>>> a = [0] * n
>>> a = [[2] * i + [1] + [0] * (n - i - 1)
for i in range(n)]
>>> for row in a:
print(' '.join([str(elem) for elem in row]))
1 0 0 0
2 1 0 0
2 2 1 0
2 2 2 1
|