0

I have a list with movie names: Movie List

And another list of questions about movies: List of questions

My objective is to loop through the list of questions and each time the function finds a name in the question that is in the list of movies, changes the name to "MOVIE". At the moment i can do it for each question: def remove_movie_name_1(text):

    for i in tqdm(range(len(movies))):
       return re.sub(movies[42], 'MOVIE', text)
remove_movie_name_1(tq[21])

This way i can change it for example from "What was the role played by Tim Allen in Toy Story 3?" to "What was the role played by Tim Allen in MOVIE?"

When i tried to apply it to the whole list I used this code:

def remove_movie_name(text):
for i in tqdm(range(len(movies))):
    return re.sub(movies[i], 'MOVIE', text)

for i in tqdm(range(len(tq))):
tq[i] = remove_movie_name(tq[i])  

But this code doesn't change anything and I can't see what's the problem. Thank you.

1 Answer 1

1
def remove_movie_name(text):
    for i in tqdm(range(len(movies))):
        return re.sub(movies[i], 'MOVIE', text)

return exits the function immediately. Your loop only runs one time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.