Sep-18-2018, 07:26 AM
Do you want to have a result like this:
I did not do the complete task. I guess it's better, when you solve the problem.
Look up for documentation about dictionaries in the Python documentation.
The get Method is very useful. It can also return default values.
{'Hemoglobin': ['10.0'], 'RBC count': ['-', '3.30'], 'HCT': ['-', '32.3'], 'MCV': ['-', '97.9'], 'MCH': ['-', '30.3'], 'MCHC': ['-', '31.0'], 'WBC count': ['9.41'], 'Neutrophils': ['77.2'], 'Eosinophils': ['-', '1.1'], 'Basophils': ['0.5'], 'Lymphocytes': ['-', '-'], 'Monocytes': ['4.9'], 'AEC': ['-'], 'Platelets': ['-', '606']}You can do this with a dict comprehension in combination with a list comprehension in one line. But you should first do it by creating two nested loops. The frist loop should iterate over the first dict and create an empty list. In the inner loop you iterate over the values (list) of the first dict. Use the
get(item, '-')
method, to get the values from the second dict. When the inner loop has been finished, you put the result in a new dict.I did not do the complete task. I guess it's better, when you solve the problem.
Look up for documentation about dictionaries in the Python documentation.
The get Method is very useful. It can also return default values.
result_dict = {} for key, values in vars.items(): result = [] for value in values: real_value = d2.get(value, '-') # code not completeI hope I did not too much.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!