[Tutor] Adding Lists?
Alan Gauld
alan.gauld at btinternet.com
Sun Aug 24 01:25:18 CEST 2008
"Emile van Sebille" <emile at fenx.com> wrote
>> yet if i wrote range (1, 500, 2) [1, 3, 5, 7....... ..499] is there
>> a command where i could total that list quickly?
>>
>
> You're looking for sum --
> sum(range (1, 500, 2) )
Or on older Python versions reduce:
import operator
s = reduce(operator.add, range(1,500,2))
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list