Hello. I need to create a function that counts using a dictionary how many different word there are in a string.
So far I have done this code:
But what I get considers the punctuation, but I need to remove the punctuation from the end of the words using the function "isalpha()". What I have done so far about this was:
But it only works for the last word of the sentence.
So, my trouble is getting to do a loop of for which searches for each word I have split in the first part of the first function to remove all the possible punctuation.
Thank you
So far I have done this code:
1 2 3 4 5 6 7 8 9 10 |
def word_distribution(text_string): text_string = text_string.lower() text_string = text_string.split() dict = {} for wd in text_string: if wd in dict : dict [wd] + = 1 else : dict [wd] = 1 return ( dict ) |
1 2 3 4 5 |
def removing(x): if x[ - 1 ].isalpha() = = True : return x else : return x[: - 1 ] |
So, my trouble is getting to do a loop of for which searches for each word I have split in the first part of the first function to remove all the possible punctuation.
Thank you