Python get for loop result into an array variable [closed]

You need to append to code each time through the loop, not assign to it. You shouldn’t reinitialize it in the loop, and the return statement should be after the loop.

And if you want a 2-dimensional list, you need to wrap the concatenations in another list.

However, the loop can be replaced completely with a list comprehension.

def getCode():
    min = 9900
    max = 9999
    return [[str(randint(min, max)) + "" + str(randint(min, max))] for _ in range(59)]

Browse More Popular Posts

Leave a Comment