بتل کد Battle Codeدارد باز می‌شود…

Followers Table چالش 1 از جلسه‌ی 35، آسان

جدول بعدی‌ها را کامل کن: برای هر کلمه (به جز آخری) کلمه‌ی بعدی را به لیستش اضافه کن. برنامه followers["the"] و followers["cat"] را چاپ می‌کند: ['cat', 'mat', 'cat', 'fish'] و ['sat', 'ate'].

text = "the cat sat on the mat the cat ate the fish"
words = text.split()

followers = {}
for i in range(len(words) - 1):
    word = words[i]
    next_word = words[i + 1]
    # add next_word to the list of word

print(followers["the"])
print(followers["cat"])

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 35: پیش‌بینی کلمه‌ی بعدی · چالش بعدی: Most Likely Next

بیشتر بخوان: حلقه for در پایتون: آموزش کامل با range و مثال