recursion

Gigs_ gigs at hi.t-com.hr
Fri Sep 14 07:40:17 EDT 2007


sorry i think that i express wrong. having problem with english


what i mean is how python knows to add all thing at the end of recursion

 >>> def f(l):
     if l == []:
         return []
     else:
         return f(l[1:]) + l[:1]


f([1,2,3])

recursion1   f([2,3]) + [1]

recursion2   f([3]) + [2]  or [2, 1]?

recursion3   f([]) + [3] or   [3, 2, 1]


i dont get all this

 >>> def f(l):
     if l == []:
	print l
         return []
     else:
         return f(l[1:]) + l[:1]

 >>> f([1,2,3])
[]
[3, 2, 1]  # how this come here? how python save  variables from each recursion?


sorry again for first post


thanks



More information about the Python-list mailing list