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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:23:49+00:00 2026-05-22T14:23:49+00:00

I used this hideous and inefficient implementation to find the word that can have

  • 0

I used this hideous and inefficient implementation to find the word that can have the most consecutive last letters removed and still be a word.

Rodeo, for example, is a well-known one: Rodeo, Rode, Rod, Ro.
The program found ‘composers’: Composers, Composer, Compose, Compos, Comp

I was wondering how I should go about creating a program that finds the longest word that can have ANY of its letters (not just the last ones) removed and it still be considered a word:

For example: beast, best, bet, be — would be a valid possibility

Here was my program to find the one that removes consecutive letters (I’m also interested in hearing how this can be improved and optimized):

#Recursive function that finds how many letters can be removed from a word and
#it still be valid.  
def wordCheck(word, wordList, counter):

    if len(word)>=1:
        if word in wordList:
            return (wordCheck(word[0:counter-1], wordList, counter-1))
        else:
            return counter
    return counter


def main():
    a = open('C:\\Python32\\megalist2.txt', 'r+')
    wordList = set([line.strip() for line in a])
    #megaList contains a sorted list of tuple of 
    #(the word, how many letters can be removed  consecutively)
    megaList = sorted([(i, len(i)-1- wordCheck(i, wordList, len(i))) for i in wordList], key= lambda megaList: megaList[1])


    for i in megaList:
        if i[1] > 3:
            print (i)

if __name__ == '__main__':
    main()
  • 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-22T14:23:49+00:00Added an answer on May 22, 2026 at 2:23 pm

    Here’s an implementation I just wrote up. It runs in about five seconds with my ~235k word list. The output doesn’t show the whole chain, but you can easily reassemble it from the output.

    # Load the words into a dictionary
    words = dict((x.strip(), set()) for x in open("/usr/share/dict/words"))
    
    # For each word, remove each letter and see if the remaining word is still
    # in the dictionary. If so, add it to the set of shorter words associated with
    # that word in the dictionary.
    # For example, bear -> {ear, bar, ber}
    for w in words:
        for i in range(len(w)):
            shorter = w[:i] + w[i+1:]
            if shorter in words:
                words[w].add(shorter)
    
    # Sort the words by length so we process the shortest ones first
    sortedwords = sorted(words, key=len)
    
    # For each word, the maximum chain length is:
    #  - the maximum of the chain lengths of each shorter word, if any
    #  - or 0 if there are no shorter words for this word
    # Note that because sortedwords is sorted by length, we will always
    # have maxlength[x] already available for each shorter word x
    maxlength = {}
    for w in sortedwords:
        if words[w]:
            maxlength[w] = 1 + max(maxlength[x] for x in words[w])
        else:
            maxlength[w] = 0
    
    # Print the words in all chains for each of the top 10 words
    toshow = sorted(words, key=lambda x: maxlength[x], reverse=True)[:10]
    while toshow:
        w = toshow[0]
        print(w, [(x, maxlength[x]) for x in words[w]])
        toshow = toshow[1:] + list(x for x in words[w] if x not in toshow)
    

    The longest word chain in my dictionary is:

    • abranchiate
    • branchiate
    • branchiae
    • branchia
    • branchi
    • branch
    • ranch
    • rach
    • ach
    • ah
    • a
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used this code to make this plot: plot(p, cv2,col=rgb(0,100,0,50,maxColorValue=255),pch=16, panel.last=abline(h=67,v=1.89, lty=1,lwd=3)) My plot
I used this tutorial to embed a collection of forms. How can I add
I used this command to find mp3 files and write their name on log.txt:
I used this link http://blog.androgames.net/85/android-accelerometer-tutorial/ to create an accelerometer. But I want that this
Used this tutorial I have installed jogl, jocl, gluegen, joal libs and added its
I used this code to maintain scroll position and don't have a clue of
I'm having some trouble figuring this out. I have a script that checks a
I have used this code to animate the circle along a fixed custom route
I have used this accepted answer to set my editor in Terminal. Unfortunately it
I used this on a form and created it like 10 times. That was

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.