I have the following code:
receps =[1,1,1,2,2,2,2,3,3,3,3,3,3]
listRecep = []
listNumRecep = []
class Line:
def __init__(self,recep) :
self.recep = recep
class Recep:
recep=""
lines = []
for recep in receps:
l=Line(recep)
if recep not in listNumRecep:
listNumRecep.append(recep)
r=Recep()
r.recep=recep
r.lines.append(l)
#print(l.recep)
listRecep.append(r)
else:
for re in listRecep:
if re.recep == recep:
re.lines.append(l)
#print(l.recep)
for re in listRecep:
print (re.lines[0].recep)
Basically what i want is to store every lines "Line" of the same "Recep" into a list contained in a "Recept" object. Then i print the recep of the first line.
So the output expected would be:
1
2
3
but actually i have
1
1
1
It looks like the first line is stored every time in the list and that's what I don't understand because when i print l.recep(commented lines) the correct output is printed so the problem is when the "Line" is affected to the "Recep".
self.recep = recep, but does not include a line that looks likeself.lines = [].recepwould be an instance ofRecep, but it is an integer in one place, and a string in another; one would assumerewould be the regexp package, but it isn't;landrare understandable in a short snippet but would be hell in a longer code (also, one might think they stand for "left" and "right", when used close together). None of this is an error, as such, but makes errors very easy, and debugging hard.