Python Loop is repeating more than 1 time -
i need loop action contains 2 lists, when try loop it, loops more 1 time each list inside. it's hard explain. here code:
import os #pregunta el path userpath=("/mnt/die/go") #hace la lista de objetos lista = ("r.alas", "r.guantes","r.cabeza","r.res") # corta la lista para tener solo objeto listacorta = [] each in lista: listacorta.append (str(each).split(".")[1]) lis in lista: r in listacorta: direccion='%s/%s_1.pc2' % (userpath, r) print lis,direccion
this get:
# r.alas /mnt/die/go/alas_1.pc2 # r.alas /mnt/die/go/guantes_1.pc2 # r.alas /mnt/die/go/cabeza_1.pc2 # r.alas /mnt/die/go/res_1.pc2 # r.guantes /mnt/die/go/alas_1.pc2 # r.guantes /mnt/die/go/guantes_1.pc2 # r.guantes /mnt/die/go/cabeza_1.pc2 # r.guantes /mnt/die/go/res_1.pc2 # r.cabeza /mnt/die/go/alas_1.pc2 # r.cabeza /mnt/die/go/guantes_1.pc2 # r.cabeza /mnt/die/go/cabeza_1.pc2 # r.cabeza /mnt/die/go/res_1.pc2 # r.res /mnt/die/go/alas_1.pc2 # r.res /mnt/die/go/guantes_1.pc2 # r.res /mnt/die/go/cabeza_1.pc2 # r.res /mnt/die/go/res_1.pc2 # ('r.alas', '/mnt/die/go/res_1.pc2') # ('r.guantes', '/mnt/die/go/res_1.pc2') # ('r.cabeza', '/mnt/die/go/res_1.pc2') # ('r.res', '/mnt/die/go/res_1.pc2')
i need 1 of each, this:
r.ala , /mnt/die/go/alas_1.pc2 r.guantes , /mnt/die/go/guantes_1.pc2
your loops
for lis in lista: r in listacorta: direccion='%s/%s_1.pc2' % (userpath, r) print lis,direccion
is causing looping. need this:
for lis in lista: direccion='%s/%s_1.pc2' % (userpath, str(lis).split(".")[1])
this way can rid of 1 loop altogether.
import os userpath=("/mnt/die/go") lista = ("r.alas", "r.guantes","r.cabeza","r.res") lis in lista: direccion='%s/%s_1.pc2' % (userpath, str(lis).split(".")[1]) print lis, direccion
Comments
Post a Comment