Duplicate processing problem when applying flip function

Asked 2 years ago, Updated 2 years ago, 14 views

I'm embarrassed because it's such a basic question, but I'm asking you because I need help in the self-study process.

Problem is

b Implement a function (filp) that generates data of the dictionary structure and stores it in the dictionary by switching keys and values. Call the function and execute it. For processing when the original data has the same value, the new dictionary stores the value as a list.

Execution Example)

flip({"Japchae": "Korean food", "Short rib soup": "Korean food", "Sushi": "Japanese food", "Black bean noodles": "Chinese food"})

{"Korean food": ["Japchae", "Galbitang", "Japanese food": ["Sushi", "Chinese food": ["Black Bean Noodles"]}

This is.

I wrote it like this, but since I realized that there is only one duplicate value, I don't think it will be processed properly. I don't even know which part to modify, so I ask for your help.

python

2022-09-20 16:57

1 Answers

Always with or without duplication:

It'll work.

I think this explanation is enough, so I'm going to shorten it.


2022-09-20 16:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.