Skip to content

Instantly share code, notes, and snippets.

@nshores
Created July 8, 2021 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshores/e6f7eaac55196400e96a2f45cea951ed to your computer and use it in GitHub Desktop.
Save nshores/e6f7eaac55196400e96a2f45cea951ed to your computer and use it in GitHub Desktop.
tinder prep.py
string = "Horse Apple Cake"
print(string)
#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 ")
else:
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:
output_arr.append(word)
return output_arr
s = "This be a string"
if s.find("is") == -1:
print("No 'is' here!")
else:
print("Found 'is' in the string.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment