Lists into Strings..?

Steve Holden sholden at holdenweb.com
Wed Aug 29 16:20:13 EDT 2001


"tefol" <tefol at This.Is.Not.An.Address> wrote in message
news:910D39579tefolThisIsNotAnAddr at 61.9.128.12...
> 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.
> :-)

>>> lExistingList = ['spam','Spam','SPAM','bacon','Bacon']
>>> sNewString = "".join(lExistingList)
>>> print sNewString
spamSpamSPAMbaconBacon
>>> sNewString = " AND ".join(lExistingList)
>>> print sNewString
spam AND Spam AND SPAM AND bacon AND Bacon
>>> print str(lExistingList)
['spam', 'Spam', 'SPAM', 'bacon', 'Bacon']
>>>
Is one of these what you were looking for?

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list