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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:44:49+00:00 2026-06-18T22:44:49+00:00

I am trying to append a list (null) with sentences which have # (Hashtags)

  • 0

I am trying to append a list (null) with “sentences” which have # (Hashtags) from a different list.
Currently my code is giving me a new list with length of total number of elements involved in the list and not single sentences.

The code snippet is given below

import re

old_list = ["I love #stackoverflow because #people are very #helpful!","But I dont #love hastags",
"So #what can you do","Some simple senetnece","where there is no hastags","however #one can be good"]

new_list = [ ]


for tt in range(0,len(s)):
    for ui in s:
        if bool(re.search(r"#(\w+)",s[tt])) == True :
            njio.append(s[tt])

Please let me know how to append only the single sentence.

  • 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-18T22:44:50+00:00Added an answer on June 18, 2026 at 10:44 pm

    I am not sure what you are wanting for output, but this will preserve the original sentence along with its matching set of hashtags:

    >>> import re
    >>> old_list = ["I love #stackoverflow because #people are very #helpful!","But I dont #love hastags",
    ... "So #what can you do","Some simple senetnece","where there is no hastags","however #one can be good"]
    >>> hash_regex = re.compile('#(\w+)')
    >>> [(hash_regex.findall(l), l) for l in old_list]
    [(['stackoverflow', 'people', 'helpful'], 'I love #stackoverflow because #people are very #helpful!'), (['love'], 'But I dont #love hastags'), (['what'], 'So #what can you do'), ([], 'Some simple senetnece'), ([], 'where there is no hastags'), (['one'], 'however #one can be good')]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select data from the database and I have the following code
I am trying to download a list of movie titles, dates and length from
I am trying to append a li element to a list with a link
B=l.append((l[i]+A+B)) l is a list here and i am trying to append into it
I have an XmlReader that is trying to read text into a list of
I have a class called LinkStrand which functions very similarly to a Linked List.
I have created CSVReader and I am trying to read csv file from assets
I am trying to append one list with another . If i pass a
i'm currently trying to get a single row from my own database, located in
I'm trying to loop results from a php script into my jquery friends list.

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.