C2, W1 assignment. Can’t solve the last (define minimum edit distance) function

Hello everyone.
Can you please tell how I can code this line?

Fill in column 0, from row 1 to row m, both inclusive

For row in range(None, None):
D[row, 0] = None

D is a matrix with the shape of (5, 5). I need to fill in the values of the firsts column (which are initially set to 0) with increasing values from 0 to 4.

Any help or idea is appreciated.

This essentially suggests you what you need to fill two arguments for the range(None, None).

Python range function’s first parameter is “start”, so as the hint suggest you need to start from row 1 (you have your first argument).

The second parameter is “stop” which is:

Required. An integer number specifying at which position to stop (not included).

In our case we need to include m, so you probably guessed it correctly :slight_smile: our second argument is m+1.

1 Like

Thank you so much. This was a huge help.
I did as you told and passed 15 out of 16 tests.
Could you please help me figure out what is the problem that one test still fails?

No problem. Do you know which test failed or any information about the case?

Sure. Here is the test that failed.
I appreciate your feedback.
Screen Shot 2022-09-08 at 20.34.33

The most common mistake to fail this test is when you hard code rep_cost value to 2. Or maybe you forgot to useallow_switches argument in edit_two_letters() function.

Thank you. I included allow_switches argument in edit_two_letters(), and that function runs smoothly. I coded the this current function like this. I think the way rep_cost is coded is also Ok.
I would appreciate if you had a look.

Oh, I see now. The problem is you assign wrong values to the first column and the first row:
D[row,0] = and D[0,col] = .

Think what should be the values for the first row and first column.
Hint, for the first column D[row,0], it should be previous row’s value + deletion cost.
As for the first row D[0,col] it should be previous column’s value + insertion cost.

P.S. please remove your solution code.

Thank you. I coded it like this, but still failed 1 test. Do you think this lines are correct?
for row in range(1, m+1):
D[row,0] = row-1 + del_cost

for col in range(1, n+1):
D[0,col] = col-1 + ins_cost

Almost. The value of the previous row is D[row-1,0] and not row-1. The same goes for the previous column.

1 Like

Right, I should have watched the formula nicely. Thank you so much.
Sorry for consuming your time. Thanks a lot again.

1 Like

Hi hitting this same one unit test failure but struggling to locate the problem?

Appreciate any help :slight_smile:

Distance matrix has wrong values.
	Expected: [[ 0  2  4  6  8 10]
 [ 2  0  2  4  6  8]
 [ 4  2  0  2  4  6]
 [ 6  4  2  0  2  4]
 [ 8  6  4  2  3  5]].
	Got: [[0 1 2 3 4 5]
 [1 0 2 4 6 7]
 [2 2 0 2 4 6]
 [3 4 2 0 2 4]
 [4 6 4 2 3 5]].
 15  Tests passed
 1  Tests failed

I have the following initial values and certainly have the allow_switches correct in the change two letter funciton.
D[row,0] = row
D[0,col] = col