The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

Random832 random832 at fastmail.com
Thu Mar 24 10:53:14 EDT 2016



On Thu, Mar 24, 2016, at 10:49, BartC wrote:
> On 24/03/2016 14:34, Jussi Piitulainen wrote:
> > You understand correctly, but it may be more natural in practice to
> > write it this way:
> >
> >      for k, item in enumerate(them):
> >          them[k] = f(item)
> >
> > I _think_ I might write it that way even when "f(item)" does not depend
> > on the old value at all, but I don't expect to be in that situation.
> >
> 
> Yes, you're right. Usually the update is conditional on the existing 
> value. But my too-simple example would have had an unneeded item
> variable.

How about them[:] = map(f, them)?



More information about the Python-list mailing list