I have a function called game()
which prints out a number.
I need to run this 500 times using
for i in range(500):
game()
but I cannot figure out how to convert this output of 500 numbers into a list.
You can create a list, and append the output of game()
into that list:
l = []
for i in range(500):
l.append(game())
Or you can just use a list comprehension like below:
l = [game() for i in range(500)]
Note that if your game()
function doesn't just return the value you want to put in a list, but print it out.
Then you have to change something like print(value)
to return value
in your game()
function. Otherwise the list l
will be full of None
.