This passes all the tests, including some additional ones that I created. It uses recursion. Here are the rules I used:
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