Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63715

Re: L[:]

Path csiph.com!usenet.pasdenom.info!goblin2!goblin3!goblin.stu.neva.ru!panix!not-for-mail
From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: L[:]
Date Sat, 11 Jan 2014 16:34:11 +0000 (UTC)
Organization PANIX Public Access Internet and UNIX, NYC
Lines 18
Message-ID <larrq2$8qh$1@reader1.panix.com> (permalink)
References <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> <mailman.5309.1389393544.18130.python-list@python.org>
NNTP-Posting-Host c-24-118-110-103.hsd1.mn.comcast.net
X-Trace reader1.panix.com 1389458051 9041 24.118.110.103 (11 Jan 2014 16:34:11 GMT)
X-Complaints-To abuse@panix.com
NNTP-Posting-Date Sat, 11 Jan 2014 16:34:11 +0000 (UTC)
User-Agent slrn/1.0.1 (Linux)
Xref csiph.com comp.lang.python:63715

Show key headers only | View raw


On 2014-01-10, Terry Reedy <tjreedy@udel.edu> wrote:
> On 1/10/2014 12:38 PM, Albert-Jan Roskam wrote:
>> In Python Cookbook, one of the authors (I forgot who) consistently used the "L[:]" idiom like below. If the second line simply starts with "L =" (so no "[:]") only the name "L" would be rebound, not the underlying object. That was the author?? explanation as far as I can remember. I do not get that. Why is the "L[:]" idiom more memory-efficient here? How could the increased efficiency be demonstrated?
>>
>> #Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2
>>>>> L = [x ** 2 for x in range(10)]
>>>>> L[:] = ["foo_" + str(x) for x in L]
>
> Unless L is aliased, this is silly code.

And if L _is_ aliaised, it's probably trying to be too clever and
needs to be fixed.

-- 
Grant


Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: L[:] Terry Reedy <tjreedy@udel.edu> - 2014-01-10 17:38 -0500
  Re: L[:] Grant Edwards <invalid@invalid.invalid> - 2014-01-11 16:34 +0000

csiph-web