Am new to python and i need help dealing so i would go ahead and post the question and my little solution so far.
Question: a Procedure which takes four parameters as follows;
Dictionary File- the file name of a text file containing four letter words
Start Word- a four letter word (that you can assume is found in the Dictionary File file)
End Word- a four letter word (that you can assume is found in the Dictionary File file)
Result File- the file name of a text file that will contain the result
The result is the shortest list of four letter words, starting with StartWord, and ending with EndWord, with a number of intermediate words that are to be found in the DictionaryFilefile where each word differs from the previous word by precisely one letter.
So far, i've been able to return true or false if the searched strings exist. I used a list because i didnt wanna use a file so i loaded sample words into a list. See my code below but i wanna achieve the above.
# create list of words
dicfile = ["ante", "ants", "calf", "call", "calm", "clam", "diet", "dire", "earl", "edit",
"emit", "erst", "fail", "fate", "feat", "feta", "ires", "irks", "item", "lair",
"lame", "late", "leap", "les", "lets", "liar", "lips", "lira","list", "lite",
"male", "mall", "mate", "matt", "meal", "meat", "mint", "mite", "mitt", "naps",
"neat", "nips", "nite", "nits", "opts", "pale", "pans", "past", "pate", "pats",
"peal", "peat", "pest", "pets", "pier", "pins", "pits", "plea", "post", "pots",
"rail", "rant", "rate", "real", "rest", "rial", "ride", "ripe", "rise", "risk",
"rite", "rite", "shin", "silt", "sire", "slip", "slit", "snap", "snip", "snit",
"span", "spat", "spin", "spit", "spot", "step", "stop", "tale", "tall", "tame",
"tans", "tape", "taps", "tare", "tarn", "teal", "team", "tear", "tide", "tied",
"tier", "tier", "tile", "time", "tine", "tins", "tint", "tips", "tire", "tire",
"tops", "lisp"]
print len(dicfile)
def is_string_in_list(startword, endword, dicfile):
for str in startword, endword:
if str not in dicfile:
return False
return True
#test the function
print (is_string_in_list("stone", "son", dicfile))