Fake Source Detector چالش 4 از جلسهی 63، متوسط
تابع find_fakes(citations) را کامل کن: برای هر منبع، اسم کتاب (قسمت قبل از () را با title_of بگیر و اگر نسخهی کوچکشدهاش (lower) در فهرست کوچکشدهی LIBRARY نبود، آن منبع را به لیست مشکوکها اضافه کن. خروجی باید این باشد:not in the library: Python Spells for Young Wizards (R. Moonfield, 2018)not in the library: The Hidden Rules of Neural Networks (K. Vale, 2031)2 of 4 sources could be made up
LIBRARY = [
"Think Python",
"Automate the Boring Stuff with Python",
"Python Crash Course",
"Invent Your Own Computer Games with Python",
]
citations = [
"Python Crash Course (Eric Matthes, 2015)",
"Python Spells for Young Wizards (R. Moonfield, 2018)",
"automate the boring stuff with python (Al Sweigart, 2015)",
"The Hidden Rules of Neural Networks (K. Vale, 2031)",
]
def title_of(citation):
return citation.split(" (")[0]
def find_fakes(citations):
known = [t.lower() for t in LIBRARY]
fakes = []
# add every citation whose lower-case title is not in known
return fakes
fakes = find_fakes(citations)
for f in fakes:
print("not in the library:", f)
print(len(fakes), "of", len(citations), "sources could be made up")
راهنما و جواب این چالش · برگشت به درس جلسهی 63: پرامپتنویسی پیشرفته ۲ · چالش بعدی: Automatic Rubric
بیشتر بخوان: list comprehension در پایتون: از حلقه for تا یک خط کد