Created
July 8, 2021 18:46
-
-
Save nshores/e6f7eaac55196400e96a2f45cea951ed to your computer and use it in GitHub Desktop.
tinder prep.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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