Failed testcase for w3_unittest.test_count_n_grams(count_n_grams)

Why 1 failed testcase ?

# Test your function

w3_unittest.test_count_n_grams(count_n_grams)

Wrong output dictionary.
	 Expected: {('-1', '-1', '-1'): 4, ('-1', '-1', 'in'): 1, ('-1', 'in', 'sunset'): 1, ('in', 'sunset', 'sky'): 1, ('sunset', 'sky', 'is'): 1, ('sky', 'is', 'red'): 1, ('is', 'red', '-2'): 1, ('-1', '-1', 'i'): 1, ('-1', 'i', 'like'): 1, ('i', 'like', 'a'): 1, ('like', 'a', 'cat'): 2, ('a', 'cat', '-2'): 2, ('-1', '-1', 'this'): 1, ('-1', 'this', 'dog'): 1, ('this', 'dog', 'is'): 1, ('dog', 'is', 'like'): 1, ('is', 'like', 'a'): 1, ('-1', '-1', 'really'): 1, ('-1', 'really', 'really'): 1, ('really', 'really', 'long'): 1, ('really', 'long', 'sentence'): 1, ('long', 'sentence', '.'): 1, ('sentence', '.', 'it'): 1, ('.', 'it', 'is'): 1, ('it', 'is', 'very'): 1, ('is', 'very', 'long'): 1, ('very', 'long', 'indeed'): 1, ('long', 'indeed', ';'): 1, ('indeed', ';', 'so'): 1, (';', 'so', 'long'): 1, ('so', 'long', '...'): 1, ('long', '...', '-2'): 1} 
	Got: {('-1', '-1', '-1'): 4, ('-1', '-1', 'in'): 1, ('-1', 'in', 'sunset'): 1, ('in', 'sunset', 'sky'): 1, ('sunset', 'sky', 'is'): 1, ('sky', 'is', 'red'): 1, ('is', 'red', '-2'): 1, ('red', '-2'): 1, ('-1', '-1', 'i'): 1, ('-1', 'i', 'like'): 1, ('i', 'like', 'a'): 1, ('like', 'a', 'cat'): 2, ('a', 'cat', '-2'): 2, ('cat', '-2'): 2, ('-1', '-1', 'this'): 1, ('-1', 'this', 'dog'): 1, ('this', 'dog', 'is'): 1, ('dog', 'is', 'like'): 1, ('is', 'like', 'a'): 1, ('-1', '-1', 'really'): 1, ('-1', 'really', 'really'): 1, ('really', 'really', 'long'): 1, ('really', 'long', 'sentence'): 1, ('long', 'sentence', '.'): 1, ('sentence', '.', 'it'): 1, ('.', 'it', 'is'): 1, ('it', 'is', 'very'): 1, ('is', 'very', 'long'): 1, ('very', 'long', 'indeed'): 1, ('long', 'indeed', ';'): 1, ('indeed', ';', 'so'): 1, (';', 'so', 'long'): 1, ('so', 'long', '...'): 1, ('long', '...', '-2'): 1, ('...', '-2'): 1}.
 5  Tests passed
 1  Tests failed

(SOLUTION CODE REMOVED BY STAFF)

1 Like

Hi @user342,

Firstly, it is against the honour code to share the solution code publicly. Please refrain from doing so.

Secondly, after looking at the code you had shared, your “range” for the “for” loop was incorrect.

Hope this helps. Happy learning!
Mubsi

Hi @Mubsi

I am facing a similar issue can you please help me.
m = len(sentence) if n==1 else len(sentence)-1
for i in range(m):

Please find my Lab ID: hoexurvt

Hi @ChandiniSaiKumarDukk,

My apologise for replying this late. I was on a vacation. But I’m back now. Is this something you still need help me ? Let me know.

Thanks,
Mubsi

Hi @Mubsi ,

Thank you for replying me back.
I found the solution, I was only considering unigrams and bigrams and neglected trigrams that is the reason some test cases failed.

Thanks
Chandini

I cannot passed this test case, please help me, I have the same problem with @ChandiniSaiKumarDukk

Hey @ChandiniSaiKumarDukk can you please help in solving this issue?

Hi bro did you get the solution

Hi can you help regarding the same issue.

Hello sir may you give me the good idea whats wrong in my loop

HI, can you please help, elaborate. please check DM.