Given two words, print the steps in turning one word into the other, or a message that it is not possible.
def transmute(word1, word2):
if len(word1) != len(word2):
print "Transmutation impossible"
transmute("word", "otherword")
Transmutation impossible
def transmute(word1, word2):
word3 = list(word1);
if len(word1) == len(word2):
for i in xrange(len(word2)):
for j in word1:
if word2[i] is j:
word3.remove(word2[i])
word3.insert(i, word2[i])
print ''.join(word3)
if ''.join(word3) != word2:
print "Transmutation impossible"
else:
print "Transmutation impossible"
transmute("door", "rood")
rdoo rodo rodo rdoo rdoo rood
transmute("door", "dorr")
door door door doro door Transmutation impossible
transmute("kitchen", "thicken")
tkichen thkicen thikcen thicken thicken thicken thicken
transmute("thicken", "kitchen")
kthicen kithcen kithcen kitchen kitchen kitchen kitchen