Answer the question
In order to leave comments, you need to log in
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'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question