جواب «Most Likely Next» چالش 2 از جلسهی 35
سؤال
تابع most_likely(word) را کامل کن که با Counter پرتکرارترین کلمهی بعدی را برگرداند. خروجی برای the و cat باید cat و sat باشد (در تساوی، Counter اولین را میدهد).
راهنما
Counter(followers[word]).most_common(1)[0][0].
یک جواب درست
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):
return Counter(followers[word]).most_common(1)[0][0]
print(most_likely("the"))
print(most_likely("cat"))
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن