C2W1 Assignment: Confusion with code after Exercise 11

In C2W1 Assignment, all unit tests passed for exercises.
But did not understand my output is correct or not.

Code snippet 1

source = "eer"
targets = edit_one_letter(source,allow_switches = False)  #disable switches since min_edit_distance does not include them
for t in targets:
    _, min_edits = min_edit_distance(source, t,1,1,1)  # set ins, del, sub costs all to one
    if min_edits != 1: print(source, t, min_edits)

Actual output:

eer ccr 2
eer ddr 2
eer kkr 2
eer hhr 2
eer ggr 2
eer qqr 2
eer yyr 2
eer ttr 2
eer xxr 2
eer uur 2
eer mmr 2
eer oor 2
eer llr 2
eer nnr 2
eer ssr 2
eer aar 2
eer rrr 2
eer jjr 2
eer vvr 2
eer ffr 2
eer bbr 2
eer wwr 2
eer ppr 2
eer zzr 2
eer iir 2

Expected output:

(empty)

Same with last code snippet also:
Code snippet 2

source = "eer"
targets = edit_two_letters(source,allow_switches = False) #disable switches since min_edit_distance does not include them
for t in targets:
    _, min_edits = min_edit_distance(source, t,1,1,1)  # set ins, del, sub costs all to one
    if min_edits != 2 and min_edits != 1: print(source, t, min_edits)

Actual output:

eer ssn 3
eer ppw 3
eer ninr 3
eer yoor 3
eer ppn 3
eer xzxr 3
eer ccrg 3
eer ffur 3
eer uurl 3
......

Expected output:

eer eer 0

Any help is appreciated.
Thanks in advance!

Imagine you have to start with the source word (β€œeer” in this case) and end with the target word. You are allowed to do only inserts, deletes and edits to the original word. min_edit_distance finds the minimum weighted sum of inserts, deletes and edits required to change the source word to the target word.

Eg:
eer β†’ uurl (order of some steps can be interchanged)

  1. Change second e to u (1 edit): eur
  2. Change first e to u (1 edit): uur
  3. Insert l at the end (1 insert): uurl

Since insert, delete and edit operations cost 1 each, the total cost of this process is 3. However, if one or more of the operations have a different cost, the steps and order may change for the cost to be minimum.

I understand your explanation. So, can I assume: Is it okay to see output not matching expected output in this case?

From the standpoint of Coursera notebooks the output and expected output will be same if:

  1. Your code is correct
  2. You edited the code only where instructed, and did not modify other parts of the code

If you wish to experiment with the code (especially for graded assignments) you should download a copy and run it elsewhere.

1 Like

Thanks for the response.