Function to count words in Python
How about using collections.Counter:

import string
from collections import Counter


def count_words(text):
    text = text.lower()
    for s in string.digits + string.punctuation:
        text = text.replace(s, "")
    text = text.split()
    return Counter(text)


print(count_words("Hello world, World War, War and Peace"))