Skip to content

Instantly share code, notes, and snippets.

Created July 8, 2021 18:46
What would you like to do?
string = "Horse Apple Cake"
#Find check if a substring is contained
#The find method returns -1 if no match, and the index where the substring starts otherwise
word = 'hello'
search = (word.find('ll'))
if (word.find('ll') != -1):
print ("Contains given substring ")
print ("Doesn't contains given substring")
#Check for a substring in an array that can be rearranged
words = ["mass","as","hero","superhero"]
class Solution(object):
def stringMatching(self, words):
#setup a empty array
output_arr =[]
#Loop through each word in the array of words
for word in words:
#Take a look at each word
for string in words:
#check to make sure the individual word doesn't match any other word exactly
if word !=string:
#Take a look at the same word and see if it can fit into another word as a string anywhere
if word in string:
#Add to the array if it's not already there
if word not in output_arr:
return output_arr
s = "This be a string"
if s.find("is") == -1:
print("No 'is' here!")
print("Found 'is' in the string.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment