Hello every ody and happy new year
i need some help
i want to write a function which copies a list
here is the code
but it doesn't work :(
it returns this
any suggestion ?
thanks a lot
PS:i have these two functions :
i need some help
i want to write a function which copies a list
here is the code
Code:
def copieIterative(l):
global l1,der,lcopie
l1=l
lcopie=None
if l1!=None :
lcopie=ajoute_Tete(lcopie,l1.val)
der=lcopie
l1=l1.suiv
while l1 != None :
der=ajoute_Tete(der,l1.val)
der=der.suiv
l1=l1.suiv
return lcopie
it returns this
Code:
>>> l=None >>> for i in range(7) : l=ajoute_Tete(l,randrange(12,68767,5)) >>> [B]l 7122 32857 38922 23662 20242 26207 8617 [/B] >>> lcopie=None >>> der=None >>> l1=None >>> v=copieIterative(l) >>> [B]v 7122 <----- the problem is here , it doesn't copie the whole list , just the first element[/B]
thanks a lot
PS:i have these two functions :
Code:
class Noeud:
def __init__(self,valeur,suivant=None):
self.val = valeur
self.suiv = suivant
def __repr__(self):
res = str(self.val)+" "
if (self.suiv != None):
res = res + str(self.suiv)
return res
def __lt__(self, autre):
return self.val < autre.val
def ajoute_Tete(L, x):
return Noeud(x, L)
Comment