Last active
June 25, 2019 13:05
-
-
Save JuliusNM/9d28930e89ab304550949a01566bd84f to your computer and use it in GitHub Desktop.
Compound word exercise
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
# Assume we have a list of words from the English dictionary, like: | |
# english_words = ["water","big","apple","watch","banana","york","amsterdam","orange","macintosh","bottle","book"] | |
# And another long list of string to process, write a function to identify "compound words" and return them: | |
# output: ["applewatch","bigbook","waterbottle"] | |
english_words = ["water","big","apple","watch","banana","york","amsterdam","orange","macintosh","bottle","book"] | |
inputWords = ["paris","applewatch","ipod","amsterdam","bigbook","orange","waterbottle"] | |
def find_compound_words(english_words, input): | |
return [input_word for input_word in inputWords for word in english_words if word in input_word and input_word[len(word):] in english_words] | |
print(find_compound_words(english_words,inputWords)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment