Lists into Strings..?

Ignacio Vazquez-Abrams ignacio at openservices.net
Wed Aug 29 16:14:33 EDT 2001


On Wed, 29 Aug 2001, tefol wrote:

> Hiya!
>
> I am wondering of the best* way to make string equal to an entire list of
> strings.
>
> >>> lExistingList = ['spam','Spam','SPAM','bacon','Bacon']
> >>> sNewString = lExistingList
>
> just doesn't seem to do it.
>
> I know that I can write the list out to a file, and then read the whole
> file in,   but that seems like so much overkill to me.
>
> Thanks heaps!
>
> tefol
>
> *I let you define best anyway you like.  That seems to be the Python way.
> :-)
>
> Cha!

In any version of Python:

---
import string
sNewString=string.join(lExistingList, '')
---

In Python 2.x:

---
sNewString=''.join(lExistingList)
---

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list