Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63951
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: L[:] |
| Date | 2014-01-14 17:07 -0500 |
| References | <lb1hvc$cog$1@ger.gmane.org> <1389696127.37654.YahooMailBasic@web163802.mail.gq1.yahoo.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5485.1389737406.18130.python-list@python.org> (permalink) |
On 1/14/2014 5:42 AM, Albert-Jan Roskam wrote: > I also found that item assignment ([1] below) is much faster > than using the more standard (I think) .append ([2]). > # [1] > for idx,item in enumerate(L[:]): > if some_condition: > L[idx] = foobarify(item) [1] *is* the standard way to selectively replace items. > # [2] > L2 = [] > for idx,item in enumerate(L): > if some_condition: > L2.append(foobarify(item)) > else: > L2.append(item) -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: L[:] Terry Reedy <tjreedy@udel.edu> - 2014-01-14 17:07 -0500
csiph-web