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 9198641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:20:00+00:00 2026-06-17T22:20:00+00:00

I thought I was understanding splits and joins in python but it is not

  • 0

I thought I was understanding splits and joins in python but it is not working right for me.

lets say the value of inp[17] = 'Potters Portland Oregon school of magic'

# a string of data I am pulling from a csv file, the data comes through just fine.
loc = inp[17] 

l = loc.split(' ') # I want to split by the space

# I want to filter out all these words say they don't always 
# come as "School of magic" so I cant just filter that out they 
# could be mixed around at times.

locfilter = ['Potters', 'School', 'of', 'magic']     
locname = ' '.join([value for value in l if l not in locfilter])

At this point my locname variable should only have Portland Oregon in it, but it still has 'Potters Portland Oregon school of magic' it didn’t filter out.

What have I done wrong I think the problem is in my locname = line.

Thanks for any help.

  • 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-06-17T22:20:02+00:00Added an answer on June 17, 2026 at 10:20 pm

    The problem here isn’t your split or join, it’s just a silly mistake in the condition in your list comprehension (the kind of silly mistake all of us make all the time):

    locname = ' '.join([value for value in l if l not in locfilter])
    

    Obviously l is never in locfilter. And if you fix that:

    locname = ' '.join([value for value in l if value not in locfilter])
    

    It works fine:

    'Portland Oregon school'
    

    Note that 'school' is still part of the output. That’s because 'school' wasn’t in locfilter; 'School' was. If you want to match these case-insensitively:

    lowerfilter = [value.lower() for value in locfilter]
    locname = ' '.join([value for value in l if value.lower() not in lowerfilter])
    

    And now:

    'Portland Oregon'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought null bytes were not allowed in shellcode. While understanding some shellcode, I
I thought this would be fairly simple but it turns out not to work
So I thought I had a good basic understanding of exception-handling in Java, but
I'm sure I'm miss understanding the use of call but I thought I could
This may be a inappropriate question for SO, but I thought lets see :)
I'm not understanding Java GUI's as well as I thought. In my paint method
I thought I had a good understanding of how quicksort works, until I watched
I believe my understanding of boost::mpl::set must be fundamentally flawed. I thought it only
I though I had a good understanding of how C++ worked but I'm confused
I thought I had resolved this but I obviously haven't and was hoping someone

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.