# Write a function that takes a sentence, # check if there are repeated words. # For each repeated word, keep track the number of time it repeats. # Your program will return a collection of the repeated words and # the number of the repetition. # Let's assume we want to use a dictionary as a data type. # Thus, a key-value pair would be # word:number # # If there is no repeated word or the file is empty, return an empty dictionary # -- that is, {} # # For example, if a sentence contains # 'I will do more more practice and my bring my my my questions to class' # # Your program will return # {'more':1, 'my':2} # 'more' repeats 1 time, 'my' repeats 2 times # def check_repeated_words(sentence): result = {} words = sentence.split() for i in range(0, len(words)-1): if words[i] == words[i+1]: if words[i] not in result: result[words[i]] = 1 else: result[words[i]] += 1 return result print(check_repeated_words('I will do more more practice and my bring my my my questions to class'))