Initialization of variables using no-arg constructor

Paul Rubin http
Mon Oct 9 18:30:31 EDT 2006


"Chris Mellon" <arkanes at gmail.com> writes:
> I'm not sure if regular slice notation makes a copy of the list or
> not, if it does you can use itertools:
> 
> >>> def sum(list):
> ...     total = list[0]
> ...     for v in itertools.islice(list, 1, len(list)):
> ...         total += v
> ...     return total
> >

import operator
def sum(list):
   it = iter(list)
   a = it.next()
   return reduce(operator.add, it, a)



More information about the Python-list mailing list