twelve days and word count exercises

This commit is contained in:
Xevion
2019-07-13 17:06:54 -05:00
parent cbd5c44d63
commit f127035e22
9 changed files with 409 additions and 1 deletions
+4
View File
@@ -0,0 +1,4 @@
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))}