from typing import Dict
import string
def word_frequency(text: str) -> Dict[str, int]:
"""Analyze text and return a dictionary of word frequencies."""
cleaned_text = text.lower().translate(str.maketrans('', '', string.punctuation))
words = cleaned_text.split()
frequency_dict = {}
for word in words:
frequency_dict[word] = frequency_dict.get(word, 0) + 1
return frequency_dict
# example text about document engineering
sample_text = "Document engineering combines programming with writing. Writing clear documents requires skill."
# analyze the text and display results
word_counts = word_frequency(sample_text)
print("Word Frequencies:")
for word, count in sorted(word_counts.items()):
print(f"'{word}': {count}")
Word Frequencies:
'clear': 1
'combines': 1
'document': 1
'documents': 1
'engineering': 1
'programming': 1
'requires': 1
'skill': 1
'with': 1
'writing': 2