بکندباز

تابعی بنویسید که یک دیکشنری از آیتم‌ها با امتیازات ستاره‌ای و یک امتیاز ستاره‌ای مشخص به عنوان ورودی بگیرد. این تابع باید یک دیکشنری جدید حاوی آیتم‌هایی که امتیاز ستاره‌ای‌شان با امتیاز مشخص‌شده مطابقت دارد، بازگرداند. اگر هیچ آیتمی مطابق امتیاز مشخص‌شده نباشد، مقدار "No results found" را برگردانید.

مثال

filter_by_rating({
  "Luxury Chocolates" : "*****",
  "Tasty Chocolates" : "****",
  "Aunty May Chocolates" : "*****",
  "Generic Chocolates" : "***"
}, "*****") ➞ {
  "Luxury Chocolates" : "*****",
  "Aunty May Chocolates" : "*****"
}

نمونه ورودی و خروجی

filter_by_rating({"Brand A": "*", "Brand B": "*****", "Brand C": "*", "Brand D": "**", "Brand E": "****", "Brand F": "*****", "Brand G": "****", "Brand H": "****", "Brand I": "*****", "Brand K": "***", "Brand L": "*****", "Brand M": "***", "Brand N": "*", "Brand O": "***", "Brand P": "*****", "Brand Q": "**", "Brand R": "****"}, "***") ➞ {"Brand K": "***", "Brand M": "***", "Brand O": "***"}

filter_by_rating({"Brand A": "*", "Brand B": "***", "Brand C": "**", "Brand D": "*****", "Brand E": "*", "Brand F": "****", "Brand G": "*****", "Brand H": "*****", "Brand I": "**", "Brand K": "*", "Brand L": "*", "Brand M": "***", "Brand N": "*", "Brand O": "*", "Brand P": "**", "Brand Q": "**", "Brand R": "****", "Brand S": "****", "Brand T": "**", "Brand U": "*", "Brand V": "*", "Brand W": "*", "Brand X": "***", "Brand Y": "*****", "Brand Z": "****"}, "**") ➞ {"Brand C": "**", "Brand I": "**", "Brand P": "**", "Brand Q": "**", "Brand T": "**"}

filter_by_rating({"Brand A": "**", "Brand B": "*", "Brand C": "*"}, "**") ➞ {"Brand A": "**"}
filter_by_rating({"Brand A": "*", "Brand B": "*****", "Brand C": "*", "Brand D": "**", "Brand E": "****", "Brand F": "*****", "Brand G": "****", "Brand H": "****", "Brand I": "*****", "Brand K": "***", "Brand L": "*****", "Brand M": "***", "Brand N": "*", "Brand O": "***", "Brand P": "*****", "Brand Q": "**", "Brand R": "****"}, "***")  ➞ {"Brand K": "***", "Brand M": "***", "Brand O": "***"}
filter_by_rating({"Brand A": "*", "Brand B": "***", "Brand C": "**", "Brand D": "*****", "Brand E": "*", "Brand F": "****", "Brand G": "*****", "Brand H": "*****", "Brand I": "**", "Brand K": "*", "Brand L": "*", "Brand M": "***", "Brand N": "*", "Brand O": "*", "Brand P": "**", "Brand Q": "**", "Brand R": "****", "Brand S": "****", "Brand T": "**", "Brand U": "*", "Brand V": "*", "Brand W": "*", "Brand X": "***", "Brand Y": "*****", "Brand Z": "****"}, "**")  ➞ {"Brand C": "**", "Brand I": "**", "Brand P": "**", "Brand Q": "**", "Brand T": "**"}
filter_by_rating({"Brand A": "**", "Brand B": "*", "Brand C": "*"}, "**")  ➞ {"Brand A": "**"}
filter_by_rating({"Brand A": "***", "Brand B": "***"}, "*****")  ➞ "No results found"
filter_by_rating({"Brand A": "*", "Brand B": "****", "Brand C": "*", "Brand D": "*****", "Brand E": "**", "Brand F": "****", "Brand G": "***", "Brand H": "****", "Brand I": "*", "Brand K": "*", "Brand L": "*****", "Brand M": "*****", "Brand N": "*", "Brand O": "**", "Brand P": "*****", "Brand Q": "**", "Brand R": "*****", "Brand S": "*****", "Brand T": "****", "Brand U": "*****", "Brand V": "*****", "Brand W": "**", "Brand X": "***"}, "**")  ➞ {"Brand E": "**", "Brand O": "**", "Brand Q": "**", "Brand W": "**"}

هنوز پاسخی برای این تمرین ثبت نشده است

نظرات

*
*

تمرینات مرتبط