string copying

Peter Hansen peter at engcorp.com
Fri Mar 29 19:44:52 EST 2002


Aahz wrote:
> 
> In article <3CA4F5CB.E8961330 at engcorp.com>,
> Peter Hansen  <peter at engcorp.com> wrote:
> >
> >The only one I've been able to think of is the surprisingly
> >common situation of trying to consume vast quantities of memory
> >quickly by something like:
> >
> >a = [0] * 1000000
> >for i in xrange(1000000):
> >    a[i] = 'bigstringsuckinguplotsofmemory'
> 
> Right, and as you know, the simple way to fix this is:
> 
> for i in xrange(bignum):
>     a[i] = "bigstringsuckinguplotsofmemory" + str(i)

...or add just 'x' instead of str(i).  I do know this, but 
I was searching for ideas as to why one would want strings 
to be copyable, as three people had just asked ...  :)

-Peter



More information about the Python-list mailing list