Learn the Weights چالش 6 از جلسهی 33، سخت
بهجای اینکه وزنها را خودمان بنویسیم، از DATA یاد بگیریم: برای هر (text, label)، هر کلمهی text اگر در weights نبود با 0 اضافه شود، بعد اگر label برابر "kind" بود +1 و وگرنه -1 بگیرد. خروجی:fun 2great 2boring -2slow -1the 0game 0
چرا the و game صفر شدند؟
DATA = [
("what a fun game", "kind"),
("the music is great", "kind"),
("fun level great idea", "kind"),
("this game is boring", "unkind"),
("the level is so slow", "unkind"),
("boring music", "unkind"),
]
weights = {}
for word in ["fun", "great", "boring", "slow", "the", "game"]:
print(word, weights.get(word, 0))
راهنما و جواب این چالش · برگشت به درس جلسهی 33: خوب یا بد؟
بیشتر بخوان: دیکشنری در پایتون: آموزش کامل کلید و مقدار با مثال