• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Lesson 8. Dictionary

Difficulty level:

Task«The merger of dictionaries»

💻 Python
two friends, Anna and Maria, decided to combine their culinary recipes. Each of them has its own dictionary, where the key is the name of the dish, and the value is the list of ingredients. Your task is to help them create one common culinary book, uniting their dictionaries. If both books have a recipe with the same name, it is necessary to combine the lists of ingredients so that the general book has a complete list of all the necessary ingredients for this dish (without repetitions).

Input format

First, the number & nbsp; n & nbsp;-the number of recipes in Anna's culinary book. Then they are introduced & nbsp; n & nbsp; lines, each line contains the name of the recipe (line) and through the gap of the ingredient list (a line separated by commas). Next, the number & nbsp; m & nbsp;- the number of recipes in the culinary book of Maria. Then, & nbsp; m lines in a similar format: the name of the recipe (line) and through the gap of the ingredient list (string separated by commas)

Output format

The United Culinary Book is displayed in the format (string) and through the gap of the ingredient list (string separated by commas). Recipes should be sorted in alphabetical order by name

Example

Input

2
Pies apple apples, flour, sugar
Vegetable cucumbers, tomatoes, onions
1
Pie apple cinnamon, flour

Output

Pies cinnamon flour sugar apple apples
salad onion vegetable cucumbers tomatoes

Hint

There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Developer’s solution

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

AI Helper

Hi! I am your programming assistant. Ask me anything about Python — I can explain functions, methods, and help you understand the current task!