Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 997733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:04:55+00:00 2026-05-16T07:04:55+00:00

Sorry if the question is bit confusing. This is similar to this question I

  • 0

Sorry if the question is bit confusing. This is similar to this question

I think this the above question is close to what I want, but in Clojure.

There is another question

I need something like this but instead of ‘[br]’ in that question, there is a list of strings that need to be searched and removed.

Hope I made myself clear.

I think that this is due to the fact that strings in python are immutable.

I have a list of noise words that need to be removed from a list of strings.

If I use the list comprehension, I end up searching the same string again and again. So, only “of” gets removed and not “the”. So my modified list looks like this

places = ['New York', 'the New York City', 'at Moscow' and many more]

noise_words_list = ['of', 'the', 'in', 'for', 'at']

for place in places:
    stuff = [place.replace(w, "").strip() for w in noise_words_list if place.startswith(w)]

I would like to know as to what mistake I’m doing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:04:55+00:00Added an answer on May 16, 2026 at 7:04 am

    Here is my stab at it. This uses regular expressions.

    import re
    pattern = re.compile("(of|the|in|for|at)\W", re.I)
    phrases = ['of New York', 'of the New York']
    map(lambda phrase: pattern.sub("", phrase),  phrases) # ['New York', 'New York']
    

    Sans lambda:

    [pattern.sub("", phrase) for phrase in phrases]
    

    Update

    Fix for the bug pointed out by gnibbler (thanks!):

    pattern = re.compile("\\b(of|the|in|for|at)\\W", re.I)
    phrases = ['of New York', 'of the New York', 'Spain has rain']
    [pattern.sub("", phrase) for phrase in phrases] # ['New York', 'New York', 'Spain has rain']
    

    @prabhu: the above change avoids snipping off the trailing “in” from “Spain”. To verify run both versions of the regular expressions against the phrase “Spain has rain”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this question seems a bit complex but I think its all related
Sorry if this question is mind numbingly easy to answer, but I'm a bit
Sorry if my last question is very similar, but I have another query of
sorry if this question seems a bit open ended, but I'm often wanting to
I'm sorry if this is a bit of a C-noob question: I know I
Sorry if this question is too vague, but I'd rather not muddy it's point
Sorry if this question is very easy, but I can't find the answer anywhere.
sorry for this question, but i dont know where to search for it, or
sorry for asking this question again but i didnt get much help on the
Sorry as the question is bit lengthy. I have this string Hello how are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.