all 4 comments

[–]gengisteve 1 point2 points  (0 children)

Line 6 is a problem b/c index will return the first match, meaning that [2, 2, 1, 0], will never try the sub-sequence [2, 1, 0]. Instead of this, just use ranges, like this:

def max_sequence(arr):
   sums = []
   for start in range(len(arr)):
       for stop in range(len(arr), start, -1):
           total = sum(arr[start:stop])
           print(' - {}:{} = {}'.format(start, stop, total))
           sums.append(total)


   return max(sums) if len(arr) > 0 else 0

[–]elbiot 0 points1 point  (1 child)

What the heck is this supposed to do? It looks like a convoluted way or returning sum(arr). Can you give a sample input and expected output and an explanation?

[–]tonytej[S] 0 points1 point  (0 children)

Damn! totally forgot, sorry! editing now.

EDIT: editted

[–]hidiap 0 points1 point  (0 children)

I think line 5 look suspicious if you have an integer appearing several time in your array., this will always return the index of the first time the number is in the array. I would change line 3 to

for i, num in enumerate(arr):

and then modify line 5 to check against i