Difference between visited = [[False] * M for _ in range(N)] and visited = [[False] * M] * N

  Kiến thức lập trình

What is the difference between visited = [[False] * M for _ in range(N)] and visited = [[False] * M] * N

Based on the visisted list declaration, I got different answers for my solution.

I hope to have an answer on this or refer me to some guides that I can read about it. Thank you.

Here is an online complier:
https://onecompiler.com/python/42bxgzxqv

New contributor

Brad Nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT