Problem
I am working on a breadth-first search algorithm for my maze solver and it is working so far. I am keeping track of the current stack by copying the previous one and appending the current value to it.
Since copying list takes a great amount of time I would like to create multiple copies of the list within one operation.
What I've tried so far
Copy the list and assign it to multiple variables.
l = [1, 2, 3] a = b = c = l[:] # Just creates references and no individual lists
Use numpy arrays with
copy
function (faster thanlist[:]
).
Question
What is the fastest way to create multiple copies of one list?