Blue Week Special Offer | Brighten your week!
days
hours
minutes
seconds

Help to understand the code on repeat old questions

I have trouble understanding the solution code, so I did the below code based on my understanding but error showed. I think the problem is at line 6-8. Solution code has list comprehension, but I want to use the for loop here. How to fix my code?

Screen Link: https://app.dataquest.io/m/210/guided-project%3A-winning-jeopardy/5/recycled-questions

My Code:

question_overlap=[]
terms_used=set()

df.sort_values(by='Air Date',ascending=True,inplace=True)

for i,row in df.iterrows():
    split_question=row['clean_question'].split()
    for i in split_question:
        if len(i) < 6:
            i.remove()
    match_count=0
    for item in split_question:
        if item in terms_used:
            match_count+=1
        if len(split_question)>0:
            match_count=match_count/len(split_question)
        question_overlap.append(match_count)
        

Hello @candiceliu93,

Kindly include the error that comes up whenever you run your code.

Also, the remove() function should be used as list_name.remove(object_to_remove). As opposed to this:

You should probably have split_question.remove(i).

1 Like