C2_W1_E9 error in Week 2 Exercise 9

In Exercise 9, I have two problems.
1- Problem in edit_two_letter()
All my prior functions work fine but edit two functions has different output. Difference in out is as below. I will appreciate any insights. (For two edit I remove all empty string and strings length > len(orignal string)+2)

2- Error in test code: w1_unittest.test_edit_two_letters(edit_two_letters)
As shown in image below it asks for set but is not able to slice it.

Thank you

Hello there,

Its not easy for us to guess where the mistake might be in the code, I would suggest to have a look at the test_edit_two_letters function in the w1_unittest which can be found in Files-> Open.

Maybe that gives you an idea as to which tests you are failing more specifically!

Thanks for the suggestion, I solved the first part.

However, there is a bug in unittest (test_edit_two_letters)

Last two tests (“Got”) were slicing the set as list see below:

    try:
        assert sorted(list(result))[:10] == sorted(
            test_case["expected"]["expected_head"]
        )
        successful_cases += 1
    except:
        failed_cases.append(
            {
                "name": test_case["name"],
                "expected": test_case["expected"]["expected_head"],
                "got": result[:10],
            }
        )
        print(
            f"First ten output values are wrong.\n\tExpected: {failed_cases[-1].get('expected')}.\n\tGot: {failed_cases[-1].get('got')}."
        )

    try:
        assert sorted(list(result))[-10:] == sorted(
            test_case["expected"]["expected_tail"]
        )
        successful_cases += 1
    except:
        failed_cases.append(
            {
                "name": test_case["name"],
                "expected": test_case["expected"]["expected_tail"],
                "got": result[-10:],
            }
        )
        print(
            f"Last ten output values are wrong.\n\tExpected: {failed_cases[-1].get('expected')}.\n\tGot: {failed_cases[-1].get('got')}."
        )

No, they convert it to list first and then slice it!

Hi @gent.spah

I believe @peeyush_sahu is correct. The “got” parts are missing the conversion to list and when the learner’s implementation does not pass the assert statement, the resulting error message would cause an error itself :slight_smile:

You are right @arvyzukai, my eyes skipped that part

It might be best for you to raise a ticked on github for this!