# Project Goal. Identify the roots of words with common prefixes,
# Strip the prefixes from the roots and save the roots in a separate list
# Print the roots that remain.# Start writing code here...
####--------------------------PREFIX_CHECK FUNCTION-------------------------------------------------#########
#write a function called prefix_check that accepts the list prefixes and the list of word_list
# follow the flow chart for the development of this list
# return roots_list to the function call for printing.
def prefix_check(pre_list, word_list):
count = 0
roots_list = []
for word in word_list:
for prefix in pre_list:
if prefix in word:
if word.startswith(prefix):
word = word[len(prefix):]
roots_list.append(word)
count += 1
return roots_list
####----------------------------PROGRAM FLOW---------------------------------------------------------########
sentence = "We should prepopulate the pregame and postgame parties before the postmortem." # use this sentence to test your code
prefixes = ['pre','post', 're'] # use the prefixes for this activity
#strip any punctuation from the sentence, but leave the spaces--this is so we get words only when we convert it to a list
count = 0
for letter in sentence:
if letter.isalnum() == False:
if letter != " ":
sentence = sentence.replace(sentence[count], " ")
count += 1
# Change the sentence into a list of words called word_list; remember,there should be no punctuation here--it should
# have been removed in the previous step.
word_list = sentence.split()
print(word_list)
# Take each word in word_list and check to see if it has any of the roots in it that you iterate over to see if they meet the qualifications below
# create a function call prefix check which has two parameters: pre_list and word_list (your function should be at the top of the program)
# pre_list contains the values passed from the prefix list and words contains the values passed from word list
# print the return value from the function (which will be a list of roots that are from the sentence)
print("Roots:", prefix_check(prefixes, word_list))