list to string

Glen Mettler gem at hsv.crc.com
Tue Feb 27 18:00:15 EST 2001


My appologies

> mylist = ['d','o','g']
> mystring = ''
> for element in mylist:
>       mystring = mystring + element

does work.  I failed to take out one of the >.

Glen

"Daniel Klein" <danielk at aracnet.com> wrote in message
news:qlfn9tkckq9g29brr0jiq2638mblclo9jn at 4ax.com...
> On Tue, 27 Feb 2001 07:22:03 GMT, Sheila King <sheila at spamcop.net> wrote:
>
> >:>>> lst =["d", "o", "g"]
> >:>>> lst
> >:['d', 'o', 'g']
> >:>>> dog = lst[0]+lst[1]+lst[2]
> >:>>> dog
> >:'dog'
> >:
> >:or is there something I'm not getting?
> >
> >Your method would be awfully tedious for very long strings. You want
something
> >that will be easy to implement, regardless of the length of the string.
> >Fortunately, several others in this thread have already suggested using
the
> >join command from the string methods.
>
> I just _know_ I'm going to get winged for this one but why not
>
> mylist = ['d','o','g']
> mystring = ''
> for element in mylist:
>       mystring = mystring + element
>
> It's simple and intuitive. I know that it has to build a _new_ string each
time
> but for shorter strings...
>
> Dan
>





More information about the Python-list mailing list