list as paremeters...
shagshag13
shagshag13 at yahooPLUSDESPAM.fr
Sun Aug 31 06:36:26 EDT 2003
hello,
i have an unexpected behaviour that i didn't understand, can someone explain
this to me ?
>>> def doit(s, stack = []):
if s == '':
return stack
stack.append(s[:1])
return doit(s[1:], stack)
>>> doit('this')
['t', 'h', 'i', 's']
>>> doit('this')
['t', 'h', 'i', 's', 't', 'h', 'i', 's']
>>> doit('this')
['t', 'h', 'i', 's', 't', 'h', 'i', 's', 't', 'h', 'i', 's']
and so on ... i would expect it to stuck to
>>> doit('this')
['t', 'h', 'i', 's']
why does this 'stack' remind of previous call ?
thanks.
More information about the Python-list
mailing list