def solution(l, t): for i in range(len(l)): for j in range(i, len(l)): if sum(l[i:j+1]) == t: return [i, j] return [-1, -1] tests = [ ([[1, 2, 3, 4], 15], [-1, -1]), ([[4, 3, 10, 2, 8], 12], [2, 3]), ] for i, o in tests: result = solution(*i) print (i, result == o, result, o)