samedi 31 mars 2018

Create lists with different amounts of random numbers Python 3

I am needing to create lists of random numbers (being either 0 or 1) with different lengths. I need lists with lengths of 10 numbers, 20 numbers, etc. all the way to 500. This is what I have:

import random
list1 = []
for x in range(10,501,10):
    list1.append(random.randint(0,1))
    print(list1)
    list1.clear()

So I'm getting 50 lists of only one random number. I understand that the range() is my problem because it is only an iterator, so what would I do to avoid writing 50 for loops to get all of these lists?




Aucun commentaire:

Enregistrer un commentaire