Your vars is essentially a mapper from full name to possible acronym form(s). Since there are 2 forms at most, and the only difference is a dot at the end, I would suggest reversed mapper with dot-less keys only
PS I would suggest to moderate spaces in your code to PEP-8 recommended. Too many spaces/empty lines bloat the code and reduce readability.
Output:In [143]: acro_2_name = {value: key for key, values in vars.items()
...: for value in values if not value.endswith('.')}
In [140]: acro_2_name
Out[140]:
{'HGB': 'Hemoglobin',
'RBC COUNT': 'RBC count',
'HCT': 'HCT',
'MCV': 'MCV',
'MCH': 'MCH',
'MCHC': 'MCHC',
'WBC COUNT': 'WBC count',
'NEUTROPHIL': 'Neutrophils',
'EOSINOPHIL': 'Eosinophils',
'BASOPHIL': 'Basophils',
'LYMPHOCYTE': 'Lymphocytes',
'MONOCYTE': 'Monocytes',
'AEC': 'AEC',
'PLATELET': 'Platelets'}
When converting results, just remove possible trailing dot - and you are good to goOutput:In [141]: {acro_2_name[result_acro.rstrip('.')]: value for result_acro, value in d2.items()}
Out[141]:
{'Basophils': '0.5',
'Eosinophils': '1.1',
'HCT': '32.3',
'Hemoglobin': '10.0',
'Lymphocytes': '16.3',
'MCH': '30.3',
'MCHC': '31.0',
'MCV': '97.9',
'Monocytes': '4.9',
'Neutrophils': '77.2',
'Platelets': '606',
'RBC count': '3.30',
'WBC count': '9.41'}
PS I would suggest to moderate spaces in your code to PEP-8 recommended. Too many spaces/empty lines bloat the code and reduce readability.
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.