mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-06 07:14:56 -06:00
4 lines
297 B
Python
4 lines
297 B
Python
import string, re
|
|
def count_words(sentence):
|
|
sentence = [x.strip(string.punctuation) for x in [word for word in re.split(r'[_,\s]+', sentence.casefold()) if len(word.strip(string.punctuation + string.whitespace)) >= 1]]
|
|
return {k : sentence.count(k) for k in list(dict.fromkeys(sentence))} |