جواب «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
راهنما
for c in citations: و if title_of(c).lower() not in known: fakes.append(c).
یک جواب درست
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 = []
for c in citations:
if title_of(c).lower() not in known:
fakes.append(c)
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")
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن