[Tutor] Noob question

Kent Johnson kent37 at tds.net
Tue Dec 11 13:19:28 CET 2007


Eric Brunson wrote:
> Hi Amit,
> 
> This is fairly inefficient.  Because strings in python are immutable 
> this approach causes a new string to be created every iteration.

This is not true of CPython (the standard python.org release) since 
version 2.4:
http://www.python.org/doc/2.4.4/whatsnew/node12.html#SECTION0001210000000000000000

Other versions of Python (Jython, IronPython, PyPy) do not have this 
optimization AFAIK.

Kent

> 
> Amit Saxena wrote:
>> The simplest way i could think of:
>>
>> a=["apple","orange","banana"]
>> b = ""
>> for i in range(len(a)):
>>      b += a[i]
>> print b


More information about the Tutor mailing list