[Tutor] converting list to string

Benoit Dupire bdupire@seatech.fau.edu
Thu, 22 Mar 2001 22:52:51 -0500


Scott wrote:

> Please forgive this question, but, I thought this:
>
>         x = ['h', 'e', 'l', 'l', 'o']
>         print str(x)
>
> would print:
>
>         hello
>
> instead I get
>
>         ['h', 'e', 'l', 'l', 'o']
>
> What am I doing wrong?  I realize it's a silly question, but these
> immutable strings just aren't being kind to me.  :-(
>
> What's the correct way to get a string from a list?  Thanks.
>

like this
>>> x = ['h', 'e', 'l', 'l', 'o']
>>>import operator
>>>a=reduce(operator.add, x)
>>> a
'hello'
>>>