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

  • Home
  • SEARCH
  • 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 6738641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:23:35+00:00 2026-05-26T11:23:35+00:00

Using Python, I want to search for, for example, ‘tune yards’ in a block

  • 0

Using Python, I want to search for, for example, 'tune yards' in a block of text that may say 'tune-yards' (with a hyphen) and it may say 'tune yards' (without). I want both to be considered matches. I’m using the find() function. Is there a good Pythonic way to treat - and spaces as one and the same, instead of just stacking elif statements?

Something like this: (I know this doesn’t work :P)

treating '-' as ' ':
    if blockOfText.find('tune yards') > -1:
        do something
  • 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-26T11:23:35+00:00Added an answer on May 26, 2026 at 11:23 am
    >>> re.search('tune[ -]yards', '58 tune yards of music')
    <_sre.SRE_Match object at 0x1ad68b8>
    >>> re.search('tune[ -]yards', '35 tune-yards of trombone')
    <_sre.SRE_Match object at 0x1ad6988>
    

    And match objects are always true (with the other possible returned value being None), so the result can be tested via if.

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

Sidebar

Related Questions

Using Python I want to be able to draw text at different angles using
I want to start using Python for small projects but the fact that a
I want to develop a GAE application using python, but I fear that Google
I want to search for images using a Python script and pull them off
I want to find the last modified file that contains a string using python.
I am writing a Python program that feeds a search term to google using
Using Python I want to randomly rearrange sections of a string based on a
Using Python's Imaging Library I want to create a PNG file. I would like
Using Python, I want to know whether Java is installed.
I want to encrypt few files using python what is the best way I

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.