list to string

Glen Mettler gem at hsv.crc.com
Tue Feb 27 17:54:15 EST 2001


I couldn't get "for element in mylist" to work but this does:

mylist = ['d','o','g']
mystring = ''
for j in range(len(mylist)):
    mystring= mystring+"".join(mylist[j])
print mystring

I am very, very new to Python so this may not be very elegant but it does
work

Glen  (I asked the original question)
Thanks for all help!


"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