when you append a list to a list, something needs to be noted:

1 a  = 1
2 b =  []
3 for i  in range(4):
4     a = a + b
5     b.append(a)

the result is right, but when the a is a list like a=[1,1,1,1]:

1 a =  [-1,-1,-1,-1]
2 b = []
3 for i in range(4):
4     a[i] = 1
5     b.append(a)

the result will be wrong with what we need.

Due to the append use the object, and the result will be the object's result.

相关文章:

  • 2022-12-23
  • 2022-01-09
  • 2021-11-29
  • 2021-05-15
  • 2021-06-19
  • 2022-02-13
  • 2021-06-25
  • 2021-10-05
猜你喜欢
  • 2021-07-18
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-11-29
  • 2022-02-13
  • 2022-01-20
相关资源
相似解决方案