2021年4月27日星期二

How to map multiple aliases back to single value in python

I'm trying to use a python dictionary so that each key has a list of strings so that any individual string from that list can be interpreted as they key itself. Not sure if that's the proper use of a dictionary or not. Relatively new to this world. Alternate solutions are welcome.

facilities = {'Name 1': ['Abr. 1', 'Alternate Name 1', 'Name1', 'Name #1'],                'Name 2': ['Abr. 2', 'Alternate Name 2', 'Name2', 'Name #2', 'Nm. 2'],                'Name 3': ['Abr 3', 'Alt Name 3', 'Name3', 'Nm. 3']}    user_input1 = 'Alternate Name 2'    user_input2 = 'Nm 3.'    user_input3 = 'Abr. 1'    user_input4 = 'Alternate Name 1'  

I'd then do some sort of operation so that operation(user_input) would return either 'Name 1', 'Name 2', or 'Name 3', depending on the value of user_input (assuming it's in one of the 3 defined lists). The 4 user_inputs listed above would produce 'Name3', 'Name2', 'Name1', and 'Name 1', respectively.

https://stackoverflow.com/questions/67293518/how-to-map-multiple-aliases-back-to-single-value-in-python April 28, 2021 at 11:51AM

没有评论:

发表评论