I have a 3d list to which I am randomly appending the string 'baddie' n number of times - in this case n = 20. I am appending randomly by generating 3 random ints which are used as the indexes to which I am appending to. What i would like is to be able to save these random sets of indexes so I can later manipulate them in my code. I was thinking I could possibly save them to a separate list as the 'for loop' iterates through generating the random values.
class board_works():
def __init__(self):
self.a = 2
self.b = 3
self.c = 5
self.board = [[[ [] for _ in range(self.a)]
for _ in range(self.b)]
for _ in range(self.c)]
def enemy_set(self):
n = 20
for count in range(0,n):
randa= random.randint(0,self.a-1)
randb= random.randint(0,self.b-1)
randc= random.randint(0,self.c-1)
self.board[randc][randb][randa].append('baddie')
n = n - 1
if n == 0:
print(self.board)
Aucun commentaire:
Enregistrer un commentaire