list to string
tdelaney at avaya.com
Wed Feb 28 02:37:46 CET 2001
> Calm down Tim, my last example was not meant as a HOWTO for
> joining strings,
> it was demonstrate how Glen's loop could be simplified by:
> 1) Iterating accross the list elements directly instead of my index
> 2) Avoiding the unnecessary use of join (since, in his example, his is
> joining a string of length 1 on each iteration).
Not a problem, but it should have been stated as such. Otherwise people like
Glen, who appears to be new to Python, will likely assume that it is the
"correct" way to do it. In fact, Glen's own posts give the impression that
he now believes that looping over the sequence himself is the "correct" way.
Whilst it will work, it is definitely sub-optimal.
In any case, I dispute your point 2. He is not joining strings of length one
on each loop - he is appending a string of length one to a string of
ever-increasing length. This is one of the the *worst* cases possible, and
he should definitely be using join() for this.
More information about the Python-list