How would I do: "if this function prints "Anagram" then print something else". I also would somehow just like to see if it would print that but not have it print it.
These are the files, I'm working on findAnagrams and comparewords cannot be changed.
comparewords.py
def word_compare(x, y='steal'):
if isinstance(x, str) and isinstance(y, str) == True:
sorted_x = sorted(x)
sorted_y = sorted(y)
if sorted_x == sorted_y:
print('Anagram')
else:
mytuple = (x, y)
print(mytuple)
else:
print("Those aren't strings!")
findtheanagram.py
from WordCompare import word_compare
def findanagram(words):
for i in words:
for j in words:
if word_compare(i,j) == "Anagrams":
print(word[i]+ ":" + j)
words = ['tar', 'rat', 'face', 'cafe', 'hello']
findanagram(words)
How do I do "if the function prints x then do x and not have it print anything"?