Clean Words Only چالش 2 از جلسهی 71، آسان
تابع tokens(text) را کامل کن: هر کلمه را کوچک کن، فقط حرفهای الفبا را نگه دار (isalpha)، و اگر خالی نبود و در STOP نبود، به لیست اضافه کن. خروجی:['sun', 'heats', 'water', 'rises']['evaporation']['rain', 'fall', 'from', 'clouds']
STOP = {"the", "a", "an", "is", "are", "and", "or", "of", "in", "on", "to", "into", "it", "this",
"that", "what", "how", "why", "does", "do", "as", "when", "they", "called", "its"}
def tokens(text):
words = []
for w in text.split():
words.append(w)
return words
print(tokens("The Sun heats the water, and it rises!"))
print(tokens("What is evaporation?"))
print(tokens("Why does rain fall from clouds?"))
راهنما و جواب این چالش · برگشت به درس جلسهی 71: RAG کوچک (۱): تکهی درست را پیدا کن · چالش بعدی: Chunks That Overlap
بیشتر بخوان: تابع در پایتون: آموزش def، پارامتر و return با مثال