# 第14章示例:词频统计(字典实战)

text = "the quick brown fox jumps over the lazy dog the fox"
words = text.split()

# 方法一:循环 + get(推荐,好理解)
freq = {}
for w in words:
    freq[w] = freq.get(w, 0) + 1

print("--- 循环版 ---")
for w, c in freq.items():
    print(f"{w}: {c}")

# 方法二:推导式版(炫技,理解即可)
freq2 = {w: words.count(w) for w in set(words)}

print("--- 推导式版 ---")
print(freq2)
