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

Step 1: Learn the Word Weights چالش 1 از جلسه‌ی 36، آسان

قدم ۱. TRAIN و TEST آماده‌اند. دیکشنری weights را از TRAIN یاد بگیر: برای هر (text, label) و هر کلمه‌ی text.split()، اگر کلمه در weights نبود با 0 اضافه شود؛ بعد +1 اگر label == "kind"، وگرنه -1. برنامه وزن پنج کلمه را چاپ می‌کند. خط اول:
love 3

TRAIN = [
    ("great game i love it", "kind"), ("so fun and so cool", "kind"), ("nice colors", "kind"),
    ("amazing work", "kind"), ("i love the music", "kind"), ("this is so cool", "kind"),
    ("great idea", "kind"), ("fun level and nice music", "kind"), ("thanks for sharing", "kind"),
    ("cool game well done", "kind"), ("the art is beautiful", "kind"), ("so funny i love it", "kind"),
    ("well done great job", "kind"), ("nice and fun", "kind"), ("the best game ever", "kind"),
    ("i like the colors", "kind"), ("beautiful work thanks", "kind"), ("very cool idea", "kind"),
    ("fun fun fun", "kind"), ("good job", "kind"),
    ("this is boring", "unkind"), ("so stupid", "unkind"), ("worst game ever", "unkind"),
    ("ugly colors", "unkind"), ("i hate it", "unkind"), ("boring and slow", "unkind"),
    ("lame idea", "unkind"), ("this is dumb", "unkind"), ("you are a loser", "unkind"),
    ("the music is awful", "unkind"), ("so slow and boring", "unkind"), ("terrible game", "unkind"),
    ("ugly and stupid", "unkind"), ("i hate this game", "unkind"), ("worst idea", "unkind"),
    ("dumb level", "unkind"), ("boring music", "unkind"), ("awful art", "unkind"),
    ("this game is lame", "unkind"), ("so bad", "unkind"),
]

TEST = [
    ("i love the art", "kind"), ("boring level", "unkind"), ("cool music", "kind"),
    ("this is the worst", "unkind"), ("so nice", "kind"), ("ugly game", "unkind"),
    ("not bad at all", "kind"), ("you are not funny", "unkind"), ("great work", "kind"),
    ("slow and lame", "unkind"),
]

weights = {}

for word in ["love", "boring", "game", "the", "fun"]:
    print(word, weights.get(word, 0))

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 36: پروژه: ناظر مهربان گالری · چالش بعدی: Step 2: Maybe Unkind, and Why

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