[issue41827] 2D array issue

2020-09-21 Thread jeet shah


jeet shah  added the comment:

after = [[1,2],[3,4]]
rows, cols = (len(after), len(after[0])) 

before = [[0]*cols]*rows

# before = [[0 for i in range(cols)] for j in range(rows)]  #uncomment this 
array definition and comment above one... see difference in output.

print(before)

def calculation(a,b):
s = after[0][0]
for x in range(a+1):
for y in range(b+1):
s += before[x][y]
before[a][b] = after[a][b] - s

def cal2():
for x in range(len(after)):
for y in range(len(after[0])):
calculation(x,y)
before[0][0] = after[0][0]
print(before)
cal2()


#expected output: [[1, 1], [2, 0]]

--

___
Python tracker 
<https://bugs.python.org/issue41827>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41827] 2D array issue

2020-09-21 Thread jeet shah


New submission from jeet shah :

See difference in output by changing array definition.

--
files: matrix summation-Copy1.ipynb
messages: 377268
nosy: jeetshahj12375
priority: normal
severity: normal
status: open
title: 2D array issue
type: behavior
versions: Python 3.10
Added file: https://bugs.python.org/file49469/matrix summation-Copy1.ipynb

___
Python tracker 
<https://bugs.python.org/issue41827>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com