BBC data exercise parse_data_from_file function test stuck

When I run the cell that tests the “parse_data_from_file” function the cell is stuck. What could be the problem? I am adding relevant codes below:

[code removed by mentor]

Hello @Mohammad_Raziuddin ,

As per the community guidelines, learners are not supposed to post code snippet solutions/notebook here. Learners can only share notebooks with mentors privately via dm.
You can post your errors and discuss solutions of the error with learners and mentors here.

So, could you kindly send me your notebook via dm such that I can check where it went wrong. By clicking on the profile picture, you will see an option to message. There you can attach your notebook. Then we can discuss the issues here, under the topic you created.

With regards,
Nilosree Sengupta

Hello @Mohammad_Raziuddin ,

I have went through your notebook. I am explaining the issues as well as how to fix below :

For # GRADED FUNCTION: remove_stopwords,

Though it gives output , there are issues.

In Your code, You have used a for loop, that iterates over each word and makes a list removes stopwords. But the thing is, it creates a new list for each word, which leads to low efficiency indeed.

To fix this issue :

  1. Remove that for loop iterating over each word to create a separate list for each word.
  2. Using list comprehension, create a new list newtext to filter the stopwords from the list
  3. Then using the join() , join the filtered words in the newtext list into a sentence as you have done.

For # GRADED FUNCTION: parse_data_from_file,

What your code does :
The remove_stopwords() method is within the nested loop.The sentence variable is only a copy that has no effect on the original list. Stopwords are removed within the loop but are not returned to the list. Hence the initial sentence list is returned.

Therefore it’s not working properly.

To fix this issue :

  1. Shift remove_stopwords() outside the nested loop.
  2. Remove the other nested loop iterating across the sentence list.
  3. The updated sentences list should be returned. Check the variables properly.

Hope this helps.

With regards,
Nilosree Sengupta

Thank you very much for you help. I was able to solve the problem with the help from your reply. Please ignore my last DM.

Hello @Mohammad_Raziuddin ,

That’s great!! You are welcome!!
Happy Learning!!

With regards,
Nilosree Sengupta

1 Like