I create a 6x5 2d array, initially with just None in each cell. I then read a file and replace the Nones with data as I read them. I create the empty array first because the data is in an undefined order in the file I'm reading. My first attempt I did this:
x = [[None]*5]*6
which resulted in some weird errors that I now understand is because the * operator on lists may create references instead of copies.
Is there an easy one liner to create this empty array? I could just do some for loops and build it up, but that seems needlessly verbose for python.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…