n = 3

arr = [
    [0,0,0],
    [0,0,0],
    [0,0,0]
]

num = 1

for i in range(n):
    if i % 2 == 0:
        for j in range(n):
            arr[i][j] = num
            num += 1
    else:
        for j in range(n - 1, -1, -1):
            arr[i][j] = num
            num += 1

for row in arr:
    print(row)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: