In Python, if l1 is a list and if we assign l2 = l1
and change l1 directly to some other list by assigning it, then l2 will also change to the list that we assigned l1 to.
It is being the case that this can be avoided by using something like this.
l2 = list(l1)
or
l2 = l1[:]
or
import copy
l2 = copy.copy(l1)
or
import copy
l2 = copy.deepcopy(l1)
For my question,
I have a 4 × 4 grid of numbers within into some type of two dimensional structured list of table
, that is being something like this:
-------------
| 0| 1| 2| 3|
|--|--|--|--|
| 4| 5| 6| 7|
|--|--|--|--|
| 8| 9|10|11|
|--|--|--|--|
|12|13|14|15|
-------------
such that table[n/4][n%4] = n
, for all values of n
, 0 ≤ n
≤ 15.
The case that, I am trying out to solve a Tic Tac Toe 4 × 4 size of board for its extended version of Spline, a game in which one of the two players must (and then should) win definitely after 14 moves by using both of the two players, unlike the drawish version of Tic Tac Toe n × n size of board, for any value of n ≥ 3 only.
For solving within this very problem, for being writing into Python,
let win = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [0, 4, 8, 12], [1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [0, 5, 10, 15], [3, 6, 9, 12]]
that which essentially corresponds enough within into four horizontal elements, four vertical elements and two diagonal elements.
I have a list
line = [[]] * 16
For all values of i
, 0 ≤ i
≤ 15, I will have to add win[item]
within into line[i]
if win[item]
contains i
.
Consider within this very following piece of code, for being written into Python,
for item in win:
for i in line:
line[i].append(item)
That is being simplifying within into,
it is being right now that,
why ever does line[i].append(item)
add the structured list of item
for all indices of structured list of line
, values of indices, 0 ≤ index ≤ 15,
but not only for the index i
of structured list of line
?
Why ever do these two very pieces of problem happen?
What ever are the alternative ways and then methods available, in order to resolve within this very following piece of issue, for being written into Python?
By making use of the same way only, I am only making use of database instead of dictionary, for the former's ability to store data in hard disk and continue computing at any period of time from its last saved state, and then I am trying to avoid using slower enough operations such as those like Multiplication, Division, Modulo and Power and making use of faster enough operations such as those like Addition, Subtraction, Logical And, Logical Or, Logical Not, Left Shift and Right Shift only.
Thank you in advance.