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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:00:32+00:00 2026-05-31T16:00:32+00:00

I’m having trouble with a program, the program takes one word, and changing one

  • 0

I’m having trouble with a program, the program takes one word, and changing one letter at a time, converts that word into the target word. Although, keep in mind that the converted word must be a legal word according to a dictionary of words that I’ve been given.

I’m having trouble figuring out how to make it recursive. The program has a limit to the amount of steps it must take.

EDIT: I’m not allowed to make holderlist Global.

My Code so far:

def changeling(word,target,steps):
    holderlist=[]
    i=0
    if steps<0 and word!=target:
        return None

    if steps!=-1:
        for items in wordList:
            if len(items)==len(word):
                i=0

                if items!=word:
                    for length in items:

                        if i==1:
                            if items[1]==target[1] and items[0]==word[0] and items[2:]==word[2:]:
                                if items==target:
                                    print "Target Achieved"
                                    holder.list.append(target)
                                holderlist.append(items)
                                changeling(items,target,steps-1)

                        elif i>0 and i<len(word)-1 and i!=1:
                            if items[i]==target[i] and items[0:i]==word[0:i] and items[i+1:]==word[i+1:]:
                                if items==target:
                                    print "Target Achieved"
                                holderlist.append(items)
                                changeling(items,target,steps-1)

                        elif i==0:
                            if items[0]==target[0] and items[1:]==word[1:]:
                                if items==target:
                                    print "Target Achieved"
                                holderlist.append(items)
                                changeling(items,target,steps-1)

                        elif i==len(word)-1:
                            if items[len(word)-1]==target[len(word)-1] and items[0:len(word)-1]==word[0:len(word)-1]:
                                if items==target:
                                    print "Target Achieved"
                                holderlist.append(items)
                                changeling(items,target,steps-1)
                        else:
                            changeling(None,None,steps-1)

                        i+=1

    return holderlist

My biggest problem is that my holding list holderlist is refreshed everytime I try to make the program recursive.

I can solve it if I input the data manually. Here’s what I want the program to do:

changeling("find","lose",4)
gives me:
['fine','fond']
the program should then do:
changeling('fine','lose',3)
gives me:
['line']
changeling('line','lose',2)
gives me:
['lone']
changeling('lone','lose',1)
gives me:
['lose']
Target Achieved
  • 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-31T16:00:33+00:00Added an answer on May 31, 2026 at 4:00 pm

    maybe something like

    def distx(w1,w2):
        if len(w1) != len(w2):return 100000
        score=0
        for i in range(len(w1)):
           score += int(w1[i] != w2[i])
        return score
    
    
    word_list = ["fine","fond","line","lose","lone"]
    
    def changeling(guess,target,steps):
        my_steps = []
        print "Guess:",guess
        if target == guess:return [guess]
        try:word_list.remove(guess)
        except:pass
        my_steps.append(guess)
        if target != guess and steps >= 0:
            this_step = []
            one_step_away = [w for w in word_list if distx(guess,w) == 1]
            for k  in one_step_away:
                print "     %s->"%guess,k
                this_step.append(changeling(k,target,steps-1))
        my_steps.append( this_step )
        return my_steps
    tmp = changeling("find","lose",4)
    print tmp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I am currently running into a problem where an element is coming back from

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.