[Tutor] Summing a list of numbers / writing small functions

Sean 'Shaleh' Perry shalehperry@attbi.com
Fri Apr 11 21:05:01 2003


>
> As soon as we have some sort of definition for summation --- as soon as we
> give it a name --- we can use it as part of our language!
>

and this name is the important thing.

for i in something:
  do something

is a loop.  I have to look at what it iterates over, what the loop is doing, 
etc to get my head around it.  When i see reduce(operator.add, foo) I know 
what is happening in one succinct bite.

This is important for OTHER people who read your code.  In python the loops 
are fairly standard but in say java or C++ replacing a loop with a named 
function is a definite win.