Y
Y
Yaroslav2022-04-15 11:36:58
Python
Yaroslav, 2022-04-15 11:36:58

Is there a standard method for looking up a dictionary of lists (one-to-many mapping)?

Several musicians play in a musical group. A virthost in a web server can have several aliases. We need a reverse lookup. (find the key by value in the list)

Of course, the task is not difficult, and I quickly wrote my own class that does this (at the input of a dict, and inside - a dictionary for reverse lookup). But doubts gnaw - it hurts, it seems to me, a simple and typical task. Maybe there is some standard library functionality for this? Maybe some special type, not exactly a dict, but with this functionality. (to add-remove elements, export to JSON, etc.)

so that there is something like

music['Beatles'] = ['John', 'Paul', 'Ringo', 'George']
music['John']  или music.some_method('John') # -> 'Beatles'
music['Beatles'] # -> 'Beatles'


Is there something standard for this, or does everyone ride their own brand of bikes?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question