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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:02:06+00:00 2026-05-25T13:02:06+00:00

I’m trying to develop a python algorithm to check if a string could be

  • 0

I’m trying to develop a python algorithm to check if a string could be an abbrevation for another word. For example

  • fck is a match for fc kopenhavn because it matches the first characters of the word. fhk would not match.
  • fco should not match fc kopenhavn because no one irl would abbrevate FC Kopenhavn as FCO.
  • irl is a match for in real life.
  • ifk is a match for ifk goteborg.
  • aik is a match for allmanna idrottskluben.
  • aid is a match for allmanna idrottsklubben. This is not a real team name abbrevation, but I guess it is hard to exclude it unless you apply domain specific knowledge on how Swedish abbrevations are formed.
  • manu is a match for manchester united.

It is hard to describe the exact rules of the algorithm, but I hope my examples show what I’m after.

Update I made a mistake in showing the strings with the matching letters uppercased. In the real scenario, all letters are lowercase so it is not as easy as just checking which letters are uppercased.

  • 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-25T13:02:06+00:00Added an answer on May 25, 2026 at 1:02 pm

    This passes all the tests, including a few extra I created. It uses recursion. Here are the rules that I used:

    • The first letter of the abbreviation must match the first letter of
      the text
    • The rest of the abbreviation (the abbrev minus the first letter) must be an abbreviation for:

      • the remaining words, or
      • the remaining text starting from
        any position in the first word.

    tests=(
        ('fck','fc kopenhavn',True),
        ('fco','fc kopenhavn',False),
        ('irl','in real life',True),
        ('irnl','in real life',False),    
        ('ifk','ifk gotebork',True),   
        ('ifko','ifk gotebork',False),    
        ('aik','allmanna idrottskluben',True),
        ('aid','allmanna idrottskluben',True),
        ('manu','manchester united',True), 
        ('fz','faz zoo',True), 
        ('fzz','faz zoo',True),
        ('fzzz','faz zoo',False),    
        )
    
    def is_abbrev(abbrev, text):
        abbrev=abbrev.lower()
        text=text.lower()
        words=text.split()
        if not abbrev:
            return True
        if abbrev and not text:
            return False
        if abbrev[0]!=text[0]:
            return False
        else:
            return (is_abbrev(abbrev[1:],' '.join(words[1:])) or
                    any(is_abbrev(abbrev[1:],text[i+1:])
                        for i in range(len(words[0]))))
    
    for abbrev,text,answer in tests:
        result=is_abbrev(abbrev,text)
        print(abbrev,text,result,answer)
        assert result==answer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.