Use list to construct a multi-dimensional array of misunderstandings

xiaoxiao2021-03-06  40

004/12/22

Yesterday uses List to construct a 2-dimensional number of M * N

Starting to write this

Self.cells = [[0] * n] * m

Subsequently assign each element, find that each line is the same

Deductively awake the List of each row pointing to the same element

a [0] IS A [1]

Return true

Such

Change the writing method

Tempcell = [0] * col

For i in inregation:

Self.cells.Append (Tempcell [:]) #copy! Not Reference

Copy content from Tempcell [:] produces a new list,

Instead of passing the reference, remember to remember!

转载请注明原文地址:https://www.9cbs.com/read-77769.html

New Post(0)