0

I got this first error[image 1] when I tried to sum +1 to a tuple, not realizing it wasnt an int, but when I try to fix it[image 2] for some reason minimum = minimum[0] bugs the previous line of code.

I've also tried other ways around it like instead of using key = lambda t: t[0] just use minimum = min(matrix[x-1][y][0], matrix[x][y-1][0], matrix[x-1][y-1][0]) but that rendered me the same exact error

1

One of your problems lies in the line

        matrix[x][y] = matrix[x-1][y-1], Operation.SUBSTITUTED

the resulting matrix[x][y] would be a tuple with two elements, first being a tuple itself. You want to use only matrix[x-1][y-1][0].

I think you should get the rest, as it seems you are trying to work around this mistake. Write a comment if you need further help, and I'll edit my answer.

And I would prefer the

minimum = min(matrix[x - 1][y][0], matrix[x][y - 1][0], matrix[x - 1][y - 1][0])

version over the two-line one, result should be the same.

Oh, and None is the action only for matrix[0][0]. The other edge elements would be deletions/insertions.

4
  • oh yea, that little silly mistake was the problem, fixed it and now it works. Thanks :) – ericnr Nov 28 '18 at 16:21
  • Does the web app show a reasonable path like "cat"->"at"->"ate" for "cat"->"ate" (and also for longer ones)? I confused insertion/deletion at some point, causing correct numbers, but wrong paths. The part you showed should be correct, though, unless I'm doing same mistake again :P – Blauelf Nov 28 '18 at 16:43
  • huh, the index page works just fine, but I get internal server error when I press the submit button. imgur.com/a/xCJ4D0A Not sure whats wrong, distances is supposedly working just fine now and returning the matrix, but it says index out of range – ericnr Nov 28 '18 at 17:29
  • Hah, that looks like the problem I had, one index becoming -1. Have you checked your values with one coordinate 0? The [0][k] would be insertions, while the [k][0] are deletions, but beware [0][0] which should stay None. You might need range(1, i) and range(1, j) on that part. I just saw you emulated nested for loops with a single while. Not that readable. – Blauelf Nov 28 '18 at 18:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .