Sep-06-2020, 01:53 PM
you can do something like this
def spam(): return 'spam' def eggs(): return 'eggs' # option 1: expand the keys menu = {('a', 'b', 'c'):spam, ('x', 'y', 'z'):eggs} menu = {key:value for item, value in menu.items() for key in item} print(menu['a']()) print(menu['z']()) # option 2: define helper function menu = {('a', 'b', 'c'):spam, ('x', 'y', 'z'):eggs} def lookup_in(lookup_key, menu): for key, value in menu.items(): if lookup_key in key: return value print(lookup_in('a', menu)())
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs