user7077252 user7077252 - 1 month ago 6
Python Question

How do I generate a set of results from a for loop?

This is my code so far:

import numpy as np

board=np.zeros((8,8))

for a in range(7):

row=board[a,0:7]


I want to create a set of this results, named all_rows, but don't know how to do it.
Thank you very much.

Answer

Create a list and append a row to that list each time through your loop:

all_rows = []
for a in range(7):

    row=board[a,0:7]
    all_rows.append(row)