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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:44:34+00:00 2026-06-12T18:44:34+00:00

new to python/programming, so not quite sure how to phrase this…. What I want

  • 0

new to python/programming, so not quite sure how to phrase this….

What I want to do is this: input a sentence, find all matches of the input sentence and a set of stored sentences/strings, and return the longest combination of matched strings.

I think the answer will have something to do with regex, but I haven’t started those yet and didn’t want to if i didn’t need to.

My question: is regex the way to go about this? or is there a way to do this without importing anything?

if it helps you understand my question/idea, heres pseudocode for what i’m trying to do:

input = 'i play soccer and eat pizza on the weekends'
focus_word = 'and'

ss = [
      'i play soccer and baseball',
      'i eat pizza and apples',
      'every day i walk to school and eat pizza for lunch',
      'i play soccer but eat pizza on the weekend',
     ]

match = MatchingFunction(input, focus_word, ss)
# input should match with all except ss[3]

ss[0]match= 'i play soccer and'
ss[1]match = 'and'
ss[2]match = 'and eat pizza'

#the returned value match should be 'i play soccer and eat pizza'
  • 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-12T18:44:35+00:00Added an answer on June 12, 2026 at 6:44 pm

    It sounds like you want to find the longest common substring between your input string and each string in your database. Assuming you have a function LCS that will find the longest common substring of two strings, you could do something like:

    > [LCS(input, s) for s in ss]
    ['i play soccer and ',
     ' eat pizza ',
     ' and eat pizza ',
     ' eat pizza on the weekend']
    

    Then, it sounds like you’re looking for the most-repeated substring within your list of strings. (Correct me if I’m wrong, but I’m not quite sure what you’re looking for in the general case!) From the array output above, what combination of strings would you use to create your output string?


    Based on your comments, I think this should do the trick:

    > parts = [s for s in [LCS(input, s) for s in ss] if s.find(focus_word) > -1]
    > parts
    ['i play soccer and ', ' and eat pizza ']
    

    Then, to get rid of the duplicate words in this example:

    > "".join([parts[0]] + [p.replace(focus_word, "").strip() for p in parts[1:]])
    'i play soccer and eat pizza'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brand new to Python (and programming in general), if this is simple and/or answered
This is probably a rudimentary question, but I'm new to threaded programming in Python
I am new to C++/Python mixed language programming and do not have much idea
I'm new to Squeak and Smalltalk but not programming in general(i've some Python experience).
I am very new to programming. I want to be able to run this
Pretty new to python/programming in general, this is my biggest project yet. I am
I'm pretty new to Python programming so I have this question: How can I
first of all I'm new to python and programming but you guys already helped
I'm relatively new to python (but not to programming), and I can't explain the
I'm quite new with Python and programming in general. My problem concerns the operations

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.