my list is being changed - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: my list is being changed (/thread-18694.html) Pages:
1
2
|
my list is being changed - ivinjjunior - May-27-2019 Hello guys, here again. i got a problem i thought would not be possible, i'v created a list for being used as a data base, just for grabbing info, i made it for not being changed , but at a point of my code it just starts to me adulterated, what makes no sense.. here is the code.. its very messy but please go easy on me.. i wanna know what is the problem.. it changes at the second loop when you type 1 instead of 0 when it asks: "continuar?".. well.. the thing is, the list : pedidosafe should not change... ever please heelp pedidos = [] dicionario = {} itens_pedido = [] pedidosafe = [] inicio = 'S' indic_pedido = 0 while inicio in 'Ss': romaneio = int(input('informe o pedido\n:')) pedido = open(f'Pedidos_test\{romaneio}.txt', 'r') cont_inicio = 0 for c, linha in enumerate(pedido): if linha.rstrip(): novo = int(linha) itens_pedido.append(novo) n = romaneio p = indic_pedido dicionario.update({p:n}) inicio = str(input('Nova entrada?\n[S/N]:')).upper().strip() indic_pedido += 1 pedidos.append(itens_pedido[:]) pedidosafe.append(itens_pedido[:]) itens_pedido.clear() analise = [] resumo = [] resumobk = [] juntar = [] pedidosbk = [] itendupl = [] tuple(pedidosafe) #APB = adicionar em pedidos backup for APB in pedidos: pedidosbk.append(APB) for q in range(0, 6): print('chegou?') print(f'{pedidosafe}pedidos safe') cont = vezes = contador = numlist = posi = ped = trigger = numped = controle = controledoresumo = menu = controle_posi = 0 if menu == 0: print('linha2') print(f'{pedidosafe}pedidossafe') for general in range(0, 7): while trigger == 0: print('\033[31m ok triger\033[m') for c, p in enumerate(pedidos): for m in p: if cont == 0: print('\033[31m ok if cont == 0\033[m') analise.append(m) if cont >= 1: print('\033[31m ok if cont >= 1\033[m') contador += 1 if m in analise: print('\033[31m ok m in analise\033[m') vezes += 1 if len(p) == contador: print('\033[31m ok len(p) == contador\033[m') resumo.append([c + controle]) resumo[posi].append(vezes) vezes = 0 contador = 0 posi += 1 if c == len(pedidos)-1: print('\033[31m ok c == len(pedidos)\033[m') for posiped in resumo: posiped.insert(0, ped) del(pedidos[0]) ped += 1 cont += 1 controle += 1 controledoresumo += 1 if controledoresumo <= 8: print('\033[31m ok controledoresumo <=8\033[m') resumobk.append(resumo[:]) resumo.clear() cont = vezes = contador = posi = 0 if len(pedidos) == 0: print('\033[31m ok len(pedidos) == 0\033[m') trigger = 1 resumobk.pop() posi = 0 resumo.clear() analise.clear() pedido1 = 0 pedido2 = 0 mai = cont2 = 0 for r in resumobk: for v in r: if cont2 == 0: print('\033[31m ok cont2 == 0\033[m') mai = v[2] pedido1 = v[0] pedido2 = v[1] if cont2 >= 1: print('\033[31m ok cont2 >= 1\033[m') if v[2] >= mai: mai = v[2] pedido1 = v[0] pedido2 = v[1] cont2 += 1 print(f'{pedidosbk}este é o pedidobak original') print(f'{pedidosafe}pedidosafe') for insert in pedidosbk: pedidos.append(insert) print(f'{pedidos}adicionando pedidosbk no pedidos') print(f'{pedidosafe}pedidosafe ponto') primeirasom = list(set(pedidosbk[pedido1]+pedidosbk[pedido2])) tuple(pedidosafe) pedidos[pedido1] = primeirasom pedidos[pedido2].clear() juntar.append(pedido1) juntar.append(pedido2) print(f'{pedidosafe}pedidosafedenovo') trigger = 0 cont2 = 0 pedido1 = 0 pedido2 = 0 controle = 0 ped = 0 pedidosbk.clear() for insert2 in pedidos: pedidosbk.append(insert2) print('essa linha?') print(f'{pedidos}este é pedidos apos ser inferido') if len(set(juntar)) >= 6: for dic in set(juntar): print(dicionario[dic]) print(f'{pedidos}pedidos') print(f'{pedidosbk}pedidosbk') print(f'{pedidosafe}pesdidossafe') for additen in pedidosafe: print(f'{juntar} este é juntar') print(f'{controle_posi} este é o controle da posição atual') print(f'{itendupl}itemdup') if controle_posi in set(juntar): print('\033[31m ok in set(juntar)\033[m') for oiten in additen: itendupl.append(oiten) controle_posi += 1 divisor = len(itendupl) dividendo = len(set(itendupl)) print(f'{divisor},{dividendo}divisor dividendo') print(f'{itendupl} agora com len {set(itendupl)}') print(f'{abs(float((dividendo / divisor) * 100 - 100)):.0f} % de redução') menu = int(input('continuar?')) print(f'{pedidosafe}pedidosafe') print(set(juntar)) controledoresumo = 0 resumobk.clear() print(f'{general}este é o contador general') print(f'{pedidos}pedidos') print(f'{pedidosbk}pedidosbk') if menu != 0: print('\033[31m ok \033[m') itendupl.clear() controle_posi = 0 pedidos.clear() pedidosbk.clear() itendupl.clear() juntar.clear() for restart in pedidosafe: pedidos.append(restart) pedidosbk.append(restart) menu = 0 break RE: my list is being changed - Yoriz - May-27-2019 The following is all the lines pedidosafe appearsLine 4: pedidosafe = [] Line21: pedidosafe.append(itens_pedido[:]) Line29: tuple(pedidosafe) Line35: print(f'{pedidosafe}pedidos safe') Line39: print(f'{pedidosafe}pedidossafe') Lin100: print(f'{pedidosafe}pedidosafe') Line104: print(f'{pedidosafe}pedidosafe ponto') Line106: tuple(pedidosafe) Line111: print(f'{pedidosafe}pedidosafedenovo') Line128: print(f'{pedidosafe}pesdidossafe') Line129: for additen in pedidosafe: Line144: print(f'{pedidosafe}pedidosafe') Line159: for restart in pedidosafe: Only Line21 alters pedidosafe
RE: my list is being changed - ivinjjunior - May-27-2019 thats whats not being logic about it all.. if u run it it will change, don't know why if you check, this line (21) is before the loop in which the program happens.. RE: my list is being changed - Yoriz - May-27-2019 I didn't check what the list contents are. If any of the items in the list are mutable they can be changed elsewhere. RE: my list is being changed - ivinjjunior - May-28-2019 my "safe list" changes exactly after this point.. And the list I am working at this stage is not related to the one that's changing .. pedidos[pedido1] = primeirasom pedidos[pedido2].clear() RE: my list is being changed - Yoriz - May-28-2019 I can't run it, it does things with files i don't have, i don't know what it doing, it's in another language. put some prints in to determine where it changes. RE: my list is being changed - ivinjjunior - May-28-2019 [[11111, 22222, 33333, 44444, 55555], [0, 77777, 88888, 22222], [22222, 11111, 33333, 44444], [11111, 0], [55555, 88888], [77777, 99999, 11111], [22222, 55555, 33333, 99999], [55555, 22222, 11111, 33333, 0, 44444, 77777]] this is the content of the list after entering the archives RE: my list is being changed - Yoriz - May-28-2019 One of the inner lists is most likely being altered innerlist1 = [11111, 22222, 33333, 44444, 55555] innerlist2 = [0, 77777, 88888, 22222] innerlist3 = [22222, 11111, 33333, 44444] innerlist4 = [11111, 0], [55555, 88888] innerlist5 = [77777, 99999, 11111] innerlist6 = [22222, 55555, 33333, 99999] innerlist7 = [55555, 22222, 11111, 33333, 0, 44444, 77777] outerlist = [ innerlist1, innerlist2, innerlist3, innerlist4, innerlist5, innerlist6, innerlist7, ] outerlistcopy = outerlist[:] print(outerlistcopy) innerlist1[0] = 99999 print(outerlistcopy)
RE: my list is being changed - ivinjjunior - May-28-2019 if you can, create a text archive named 100 with the content: 11111 22222 33333 44444 55555 other named: 200: 00000 77777 88888 22222 300: 22222 11111 33333 44444 400: 11111 00000 500: 55555 88888 600: 77777 99999 11111 700: 22222 55555 33333 99999 800: 55555 22222 11111 33333 00000 44444 77777 it might work and you will see exactly what is the point.. when you press the last number which is 800 type "N" and then press number 0 four times it will show a percentage value then press 1 and it will start the whole process again, but the percentage value is gonna be zero because the list named "pedidosafe" is gonna be changed from what it was in the first loop.. i need the second loop to give me the same percentage value always.. you might also see in the prints the "pedidosafe" before and after the loop and the complete difference it has.. RE: my list is being changed - Yoriz - May-28-2019 pedidos.append(itens_pedido[:]) pedidosafe.append(itens_pedido[:]) pedidos and pedidosafe have the same inner items, pedidos is probably altering the inner items.
|