So, I'm not entirely sure how to phrase this question, but I'm going to give it my best shot.
I have a string target as well as a string initial. Both strings contain only the characters 'A' or 'B'. We can assume initial is in string. My program runs through target and attempts to reduce it to initial, like so:
def check_string(target, initial):
if initial == target:
print('Possible')
else:
if initial in target:
if (target[len(target)-1]) == 'A':
move_A(target)
elif target[0]=='B':
move_B(target)
else:
print("Not Possible")
where move_A and move_B are the functions
def move_A(word):
word_list=create_list(word)
del (word_list[len(word_list)-1])
new_word=''.join(word_list)
print(word)
check_string(new_word, initial)
def move_B(word):
word_list=create_list(word)
del word_list[0]
word_list.reverse()
new_word=''.join(word_list)
print(word)
check_string(new_word, initial)
respectively.
This works, unless the letter that is trying to check/delete is one of the characters that is used to spell initial. How do I check to see if a specific character in one string is one of the characters used to make-up another string. I really hope this makes sense, and thanks!
Aucun commentaire:
Enregistrer un commentaire