[Tutor] General design question

Daniele d.conca at gmail.com
Wed Jul 2 12:31:32 CEST 2008

>> If I have a set of numbers, or strings etc. which have been generated and I then want to do something with them, for example a sum function call.  Is the best way to put those items in a list, or similar container, before applying the function.
> Not only "best" but "necessary". the sum () builtin takes an
> iterator -- often a list, but needn't be -- of numbers.

I'm a total newbie, but wouldn't it be possible to use a set (from
which I think you can get an iterator)?
By the way, if you only need to sum a range(n, m) you can use the
formula [ m*(m-1) - n*(n-1) ] / 2 or the equivalent (m+n-1)*(m-n)/2.
Sorry for pointing out this last thing, of course it is not general at
all, but maybe you'll find it useful anyway.


More information about the Tutor mailing list