Most Likely Next چالش 2 از جلسهی 35، آسان
تابع most_likely(word) را کامل کن که با Counter پرتکرارترین کلمهی بعدی را برگرداند. خروجی برای the و cat باید cat و sat باشد (در تساوی، Counter اولین را میدهد).
from collections import Counter
followers = {"the": ["cat", "mat", "cat", "fish"], "cat": ["sat", "ate"], "sat": ["on"], "on": ["the"], "mat": ["the"], "ate": ["the"]}
def most_likely(word):
pass
print(most_likely("the"))
print(most_likely("cat"))
راهنما و جواب این چالش · برگشت به درس جلسهی 35: پیشبینی کلمهی بعدی · چالش بعدی: Build the Table in a Function
بیشتر بخوان: تابع در پایتون: آموزش def، پارامتر و return با مثال