Skip to content

Instantly share code, notes, and snippets.

@AntiKnot
Created June 20, 2021 05:36
Show Gist options
  • Select an option

  • Save AntiKnot/3f6dd822daadea09d39d8c099446b29d to your computer and use it in GitHub Desktop.

Select an option

Save AntiKnot/3f6dd822daadea09d39d8c099446b29d to your computer and use it in GitHub Desktop.
python init 2vector matrix
# right
def init_matrix(n,m):
return [[0 for _ in range(n)] for _ in range(m)]
# wrong
# In this way, the rest of the positions will also be modified when the value is modified.
def init_matrix_wrong(n,m):
return [[0] * n] * m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment