On 23 February 2012 21:23, Buck Golemon <b...@yelp.com> wrote: > def sum(values, > base=0): > values = > iter(values) > > try: > result = values.next() > except StopIteration: > return base > > for value in values: > result += value > return result
This is definitely not backward compatible. To get something that has a better chance of working with existing code, try this (untested): _sentinel = object() def sum(iterable, start=_sentinel): if start is _sentinel: iterable = iter(iterable) try: start = iterable.next() except StopIteration: return 0 for x in iterable: start += x return start del _sentinel -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list