Reputation: 271
This is for a school project. It is a program that returns the shortest path from a start word to another end word using BFS. I have to crosscheck the start word with a list of words I have and save that word in a list called children. I would like to print the list Children when I ran the program. Why don't I see the list Children when I ran the program?
import bintree
import imp
imp.reload(bintree)
from queuelist import Queue
class Word:
def __init__(self, w, f = None):
self.word = w
self.parent = f
filename = 'word3u'
fin=open(filename,'r')
tree = bintree.Bintree()
alist = fin.readlines()
lista='abcdefghijklmnopqrstuvwxyz'
doubles=bintree.Bintree()
for ord in alist:
word=ord.strip()
tree.put(word)
def generator(parent):
children=[]
theWord=parent.word
doubles.put(theWord)
#print(theWord)
n=0
while n<3:
for i in lista:
if n==0:
theWord=i+theWord[1:]
#print("1 "+theWord)
if n==1:
theWord=theWord[0]+i+theWord[2]
#print("2 "+theWord)
if n==2:
theWord=theWord[0:2]+i
#print("3 "+theWord)
if tree.exists(theWord):
#print("THIS " + theWord)
if not doubles.exists(theWord):
#print("THIS 2 " + theWord)
children.append(Word(theWord, parent))
doubles.put(theWord)
theWord=parent.word #reset theWord for next n
n+=1
return children
generator(Word("fan"))
Upvotes: 2
Views: 66
Reputation: 107287
Since you returned the childeren
in your function you need to print your object when you call it.So just do the following :
print(generator(Word("fan")))
Upvotes: 2