string copying

Carl Banks imbosol at vt.edu
Sun Mar 31 22:25:00 EST 2002


Peter Hansen wrote:
> phil hunt wrote:
>> 
>> On Fri, 29 Mar 2002 18:16:27 -0500, 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'
>> 
>> Simpler is range(1000000)
> 
> Yeah, I know.  I think you and Aahz missed my (admittedly puny)
> point, which was to hypothesize _at least one case_ where it
> was conceivably desirable by someone to try to copy a string.

Perhaps he wanted to use the strings as some sort of serial number and
message in one, i.e., something a not-trying-to-be-clever programmer
would implement as a tuple or class.  For example:

    # checking to see if two messages refer to the same event,
    # in which case print the message only once
    if a is b:
        print a
    else:
        print a
        print b


-- 
CARL BANKS                                http://www.aerojockey.com
"Nullum mihi placet tamquam provocatio magna.  Hoc ex eis non est."



More information about the Python-list mailing list