list parameter of a recursive function

TP Tribulations at Paralleles.invalid
Thu Oct 7 07:25:07 CEST 2010

Diez B. Roggisch wrote:

> Back to your example: your solution is perfectly fine, although a bit
> costly and more error-prone if you happen to forget to create a copy.
> A safer alternative for these cases is using tuples, because they are
> immutable.

Thanks Diez for your explanation.
The problem with tuples is that it is not easy to modify them: in my case, I 
need to append a string to the tuple at each recursive step.
So, it seems to me that I need to write a loop to modify the tuple, because 
on a simple example:

>>> a=("foo", "bar")
>>> b=(a[0],a[1],"toto")
>>> b
(u'foo', u'bar', u'toto')

I do not find any other means to obtain that result for b. With lists, I can 
use ".extend()".
Am I right?

python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)

More information about the Python-list mailing list