def char_check(x,y):
if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
return True
else:
return False
print "You will enter two words that you think use some of the same letters."
x = raw_input('Enter one of the words: ')
y = raw_input('Enter the other word: ')
print char_check(x,y)
What I am trying to do is enter two strings, such as "terrible" for str(x) and "bile" for str(y) and return "True" because the characters 'b', 'i', 'l', and 'e' are shared by both strings.
I'm new and trying to learn but I couldn't seem to figure this one out on my own. Thanks y'all.
Sets are almost certainly the way to go.
>>> set1 = set("terrible")
>>> set2 = set("bile")
>>> set1.issubset(set2)
False
>>> set2.issubset(set1) # "bile" is a subset of "terrible"
True
>>> bool(set1 & set2) # at least 1 character in set1 is also in set2
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With