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


Groups > comp.lang.python > #63951 > unrolled thread

Re: L[:]

Started byTerry Reedy <tjreedy@udel.edu>
First post2014-01-14 17:07 -0500
Last post2014-01-14 17:07 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: L[:] Terry Reedy <tjreedy@udel.edu> - 2014-01-14 17:07 -0500

#63951 — Re: L[:]

FromTerry Reedy <tjreedy@udel.edu>
Date2014-01-14 17:07 -0500
SubjectRe: L[:]
Message-ID<mailman.5485.1389737406.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web