How to efficiently proceed addition and subtraction in python list?

Simon Brunning simon at brunningonline.net
Tue Sep 19 09:16:30 EDT 2006


On 18 Sep 2006 15:43:31 -0700, Daniel Mark <danielmarkhot at gmail.com> wrote:
> Hello all:
>
> I have a list AAA = [1, 2, 3] and would like to subtract one from list
> AAA
> so AAA' = [0, 1, 2]

You've had some excellent suggestions as to how to go about this
assuming that by "efficient" you mean in terms of CPU. If, instead,
you are concerned with memory usage, you might instead do something
like:

for index, value in enumerate(AAA):
    AAA[index] = value-1

-- 
Cheers,
Simon B,
simon at brunningonline.net



More information about the Python-list mailing list