stoiclion's picture
Agent Workbench tasks and environment at e59670df
b5d1dbc verified
Raw History Blame Contribute Delete
275 Bytes
def top_words(text, k):
"""The k most frequent lowercase words; ties broken alphabetically. Words are runs of letters."""
import re
from collections import Counter
counts = Counter(re.findall(r"[a-z]+", text))
return [w for w, _ in counts.most_common(k)]