0
Two dimensional array python
I am having problem with two dimensional array in python. I explained my problem in the code. https://code.sololearn.com/csVYFqkb7k54/?ref=app
1 Antwort
+ 5
What happened there is that you are getting a shallow copy of temp into plist. Do a deep copy instead so that the list contents remain even after changing temp repeatedly within the loop. Else, plist contents will change according to temp.
import copy
def power_list(list):
plist=[]
l=len(list)
for i in range(l):
temp=[]
for j in range(i,l):
temp.append(list[j])
print(temp)
plist.append(copy.deepcopy(temp))
print(plist)
list=[2,3,4]
power_list(list)
Ref:
https://docs.python.org/3.8/library/copy.html