تم الحل ✓
categoryبرمجة وتطوير البرمجيات
schoolبكالوريوس
event_available2026-07-14
السؤال
Transcribed Image Text:
2. You are given a 2-D list. Every list has a dish and the ingredients used in it. Your task is to group
the dishes by ingredients. Include the dish only if it is made by more than 1 ingredient.
Also, the output should be in alphabetical order of the ingredients.
You need to write a function for this task.
Example:
Input [["Salad", "Tomato", "Cucumber", "Salad", "Sauce"],
["Pizza", "Tomato", "Sausage", "Sauce", "Dough"],
["Quesadilla", "Chicken", "Cheese", "Sauce"],
["Sandwich", "Salad", "Bread", "Tomato", "Cheese"]]
Solution:
Output = [["Cheese", "Quesadilla", "Sandwich"],
["Salad", "Salad", "Sandwich"],
["Sauce", "Pizza", "Quesadilla", "Salad"],
["Tomato", "Pizza", "Salad", "Sandwich" ]]
Explanation: 1st element of input list i.e. Salad, Pizza, Quesadilla, Sandwich are
names of dishes. The remaining elements are the ingredients used.
In the output, 1st element is the ingredient name and the remaining elements are the
dishes made from them. Also note that the output is sorted by names of the
ingredients.
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.