mardi 2 novembre 2021

Why does this python code seems to fill all list entries with same sequence of numbers? [duplicate]

import random
n=5
list = [[None]]*n
for i in list:
    i[0] = random.uniform(0,1)

print(list)

No matter the value of n, all list entries seem to always end up getting the same value. Why?

(For context, i was trying to fill a matrix with random numbers)




Aucun commentaire:

Enregistrer un commentaire