0
>>> c
[['1', '1', '1', '1'], ['1', '1', '1', '1'], ['1', '1', '1', '1'],      ['1', '1', '1', '1']]
>>> c[1][1] = 'B'
>>> c
 [['1', 'B', '1', '1'], ['1', 'B', '1', '1'], ['1', 'B', '1', '1'], ['1', 'B', '1', '1']]
>>> c[0][1] = 'A'
>>> c
[['1', 'A', '1', '1'], ['1', 'A', '1', '1'], ['1', 'A', '1', '1'],    ['1', 'A', '1', '1']]

Heading Can anybody explain when I just want to change the vaule c[0][1], python changes all c[every num in range(4)][1]?

Nyaruko
  • 19
  • 3
  • 1
    You defined `c` as something like `[['1', '1', '1', '1']] * 4`. Shouldn't do that, that makes a list with four copies of the same list. Do `[['1', '1', '1', '1'] for _ in range(4)]` and it will work as you expect. – David Robinson Aug 06 '15 at 02:18
  • see this: http://stackoverflow.com/questions/17702937/generating-sublists-using-multiplication-unexpected-behavior – NightShadeQueen Aug 06 '15 at 02:21
  • or this: http://stackoverflow.com/questions/30703303/unexpected-behaviour-of-nested-lists-in-python – NightShadeQueen Aug 06 '15 at 02:22

0 Answers0