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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:14:38+00:00 2026-06-14T20:14:38+00:00

If I have a string and want to return a word that includes a

  • 0

If I have a string and want to return a word that includes a whitespace how would it be done?

For example, I have:

line = 'This is a group of words that include #this and @that but not ME ME'

response = [ word for word in line.split() if word.startswith("#") or  word.startswith('@')  or word.startswith('ME ')]

print response ['#this', '@that', 'ME']

So ME ME does not get printed because of the whitespace.

Thanks

  • 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-14T20:14:38+00:00Added an answer on June 14, 2026 at 8:14 pm

    You could just keep it simple:

    line = 'This is a group of words that include #this and @that but not ME ME'
    
    words = line.split()
    
    result = []
    
    pos = 0
    try:
        while True:
            if words[pos].startswith(('#', '@')):
                result.append(words[pos])
                pos += 1
            elif words[pos] == 'ME':
                result.append('ME ' + words[pos + 1])
                pos += 2
            else:
                pos += 1
    except IndexError:
        pass
    
    print result
    

    Think about speed only if it proves to be too slow in practice.

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

Sidebar

Related Questions

I have a string pc1|pc2|pc3| I want to get each word on different line
I have a method that returns a list of type string. I want to
I have a string that I want passed via the linebreaks filter. {% trans
I have a string that I want to have PHP read as a piece
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have this string: Test: String And I want to select the text before
I currently have a regex pattern that matches a specific word, which includes arbitrary
I have this small program that reads a line of input & prints the
I have written two methods that take and return a string. One converts from
I have a JSON response that looks like this. I want to extract the

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.