[Tutor] Mutable String Question
Don Arnold
Don Arnold" <darnold02@sprynet.com
Mon Aug 4 07:34:01 EDT 2003
----- Original Message -----
From: "Marc Barry" <marc_barry@hotmail.com>
To: <tutor@python.org>
Sent: Monday, August 04, 2003 4:56 AM
Subject: [Tutor] Mutable String Question
> All:
>
> Is there a mutable string type such as a string buffer in Python? I know
> that string's in Python are immutable and therefore you cannot append to
> them. It seems terribly inefficient to do something like the following:
>
> #------
>
> a_string = ""
> word_list = ["My", "name", "is"]
>
Replace these 2 lines:
> for word in word_list:
> a_string = a_string + " " + word
>
with this one:
a_string = ' '.join(word_list) ## note that there's a space between the
quotes
> print a_string
>
> #------
>
> I know that the above is a trivial example, but with the amount of text I
am
> processing this could have a significant impact on performance. Does
anyone
> know of a better way to handle this?
>
> Regards,
>
> Marc
HTH,
Don
More information about the Tutor
mailing list