<s>Human: 请写一个Python函数，计算一个字符串中每个单词出现的频率。
def word_freq(string):    # your code herestring = "this is a word, not a letter. This word appears many times in this string!"
</s><s>Assistant: def word_freq(string):
    words = string.lower().split()  # 将字符串小写，分割成单词列表
    freq = {}
    for word in words:
        word = word.strip('.,!')  # 去除单词前后的标点符号
        if word not in freq:
            freq[word] = 1
        else:
            freq[word] += 1
    return freq

string = "this is a word, not a letter. This word appears many times in this string!"
print(word_freq(string))  # {'this': 2, 'is': 1, 'a': 2, 'word': 2, 'not': 1, 'letter': 1, 'appears': 1, 'many': 1, 'times': 1, 'in': 1, 'string': 1}
</s>