string copying

phil hunt philh at comuno.freeserve.co.uk
Sat Mar 30 17:55:04 EST 2002


On Fri, 29 Mar 2002 18:16:27 -0500, Peter Hansen <peter at engcorp.com> wrote:
>Jeff Shannon wrote:
>> 
>> In article <AZ3xhtAObNp8EwwK at jessikat.fsnet.co.uk>,
>> robin at jessikat.fsnet.co.uk says...
>> > Is there some special reason why python inhibits string copying. I
>> > suppose there's some attempt being made to make these constants. To make
>> > differing versions of 'abc' one has to resort to silliness like 'ab'+'c'
>> 
>> 1) Strings are immutable.  This implies that there is zero
>> practical difference between two references to two separate
>> string objects of identical value, and two references to the same
>> string object.
>
>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'

Simpler is range(1000000)


-- 
<"><"><"> Philip Hunt <philh at comuno.freeserve.co.uk> <"><"><">
"I would guess that he really believes whatever is politically 
advantageous for him to believe." 
                        -- Alison Brooks, referring to Michael
                              Portillo, on soc.history.what-if



More information about the Python-list mailing list