Apr-23-2021, 02:22 PM
(Apr-23-2021, 10:49 AM)ibreeden Wrote: If I understand your logic well, you are first adding all words to a dictionary. Then you are doing a lot of work to inspect the dictionary and move the words starting with a capital to the same word in lower case and delete the word starting with a capital.
My advice would be: make all keys lower case in the first place. Then the dictionary needs no post-processing.
freq = {} for sentence in sentences: words = re.split(r"[^a-zA-Z0-9-]+", sentence) for word in words: count = freq.get(word.lower(), 0) freq[word.lower()] = count + 1