String.join revisited (URGENT for 1.6)

Duncan Booth duncan at rcp.co.uk
Fri Jun 9 06:31:50 EDT 2000


mjhand at concentric.net (Manus Hand) wrote in
<394003D6.366D0B0 at concentric.net>: 

>But as the devil's advocate, tt just seems to me
>that [].join() could be implemented such that each member of the list is
>str()'ed or repr()'ed and then stuck together in the result string.  I
>imagine that one of the fatal flaws in this, though, is how self
>-referential lists would be handled: 
>   >>> x = ['a']
>   >>> x.append(x)
>   >>> x.join()        # I would argue we get an exception?
>

There is no problem with recursion here. What you are proposing is that
x.join() is equivalent to:
 >>> string.join(map(str, x))
 "a ['a', [...]]"

As you see the str function already handles recursive lists.



More information about the Python-list mailing list