How to efficiently proceed addition and subtraction in python list?

Tim Chase python.list at tim.thechases.com
Mon Sep 18 18:47:52 EDT 2006


> I have a list AAA = [1, 2, 3] and would like to subtract one from list
> AAA
> so AAA' = [0, 1, 2]
> 
> What should I do?


Sounds like a list comprehension to me:

 >>> a = [1,2,3]
 >>> a_prime = [x-1 for x in a]
 >>> a_prime
[0, 1, 2]

-tkc






More information about the Python-list mailing list