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".