I've got a problem. In python I've got an function, which should print the longest path. The function works, if I use a list like [[1,2,3,4,5][1,2,3,4,5]] but if I use list like [x] for x in range(5)]*2, or any other list like that. (I don't know what is this called in python, but if I have list like [vale]*something), the code doesn't work.
So, my question is, how can I make new list, without any references. Deepcopy or [:] doesn't work, because references inside list, are still there. But I don't know how to copy just values, without references. :) Thanks.
def naj_narascajoca(vrtek):
visina = len(vrtek)
sirina = len(vrtek[0])
vrt = []
vrt.append([-1]*(sirina+2))
for greda in vrtek:
greda.insert(0,-1)
greda.append(-1)
vrt.append(greda)
vrt.append([-1]*(sirina+2))
for i in vrt:
print(i)
pot = ""
maximal = 0
je_vecja = True
x = 1
y = 1
max_odlocitev = 0
while je_vecja == True:
print("--------------",vrt[x][y],"-----------------")
vre_left = vrt[x][y-1]
vre_right = vrt[x][y+1]
vre_up = vrt[x-1][y]
vre_down = vrt[x+1][y]
sez = sorted([vre_down,vre_left, vre_right, vre_up])
for i in sez:
if i > maximal:
max_odlocitev = i;
break
#max_odlocitev = max(vrt[x][y-1],vrt[x][y+1], vrt[x+1][y], vrt[x-1][y])
if maximal < max_odlocitev:
maximal = max_odlocitev
if vrt[x][y-1] == maximal:
pot += "L"
y -=1
elif vrt[x][y+1] == maximal:
pot += "R"
y+=1
elif vrt[x+1][y] == maximal:
pot += "D"
x+=1
elif vrt[x-1][y] == maximal:
pot += "U"
x-=1
else:
je_vecja = False
print(pot)
vrt = [[1,3,3,8,5,4,2,1,5,6],
[2,4,3,3,6,8,1,3,5,6],
[4,5,6,4,7,4,3,6,4,7],
[2,8,7,0,0,7,4,7,8,0],
[2,3,4,7,0,8,7,6,3,8],
[3,7,9,0,8,5,3,2,3,4],
[1,5,7,7,6,4,2,3,5,6],
[0,6,3,3,6,8,0,6,7,7],
[0,1,3,2,8,0,0,0,0,0],
[3,1,0,3,6,7,0,5,3,1],
[1,3,5,7,0,8,6,5,3,1],
[3,6,3,1,3,5,8,7,5,1],
[4,3,6,0,0,8,4,7,5,3],
[3,5,6,8,6,3,1,3,5,2]]
#naj_narascajoca(vrt)
naj_narascajoca([[x] for x in range(5)]*2)