L[:]
Terry Reedy
tjreedy at udel.edu
Tue Jan 14 17:07:15 EST 2014
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
More information about the Python-list
mailing list