0

I'm trying to use dictionary with multiple keys assigned to one value.

For example:

my_arg = 'MARY'
my_dict = {('Al','AMY','45'): 'ZONE1', 
           (56,'LO','MARY','ELM'): 'ZONE2',
           (75,'SF','KIM','CORE'): 'ZONE3'}

I need to get the value if one passed argument matches one of the keys.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 3
    That's not a dictionary with multiple keys assigned to one value, it's a dictionary with tuple keys. You could expand that to the former if you wanted to, then the lookup would be trivial. – jonrsharpe Jan 06 '22 at 19:39
  • 1
    `{k2: v for k1, v in my_dict.items() for k2 in k1}`. – chepner Jan 06 '22 at 19:46
  • Welcome to Stack Overflow! Check out the [tour]. I closed the question because it seems to be a duplicate of an earlier question. If that's incorrect, please [edit] and clarify what makes this different, as well as what research you've already done. For more tips, see [ask]. – wjandrea Jan 06 '22 at 20:03

0 Answers0