python: merging dictionaries by identical value of key [duplicate]
Internet of Things
IoT Frameworks
2 years ago
5
Star Rating
1
Rating
_x000D_
_x000D_
_x000D_
This question already has an answer here:_x000D_
_x000D_
_x000D_
How to merge two dictionaries in a single expression?_x000D_
_x000D_
41 answers_x000D_
_x000D_
_x000D_
_x000D_
_x000D_
I am new to python and have looked at other answers on merging dictionaries but was still a bit confused.
I am looking to merge together two dictionaries in python by a common value within a specific key to output that common key with the other keys from both dictionaries in a new dictionary.
Here is sample data:
add_sal = {'career_medicine': None, 'career_law': None, 'median_salary': None, 'mean_salary': 75000.0, 'career_business': 'operations / logistics', 'number': None}
add_perc = {'percent': 0.07, 'career_business': 'operations / logistics'}
I would like to merge on the key value pair of 'career_business': 'operations / logistics'
and output a dictionary that looks like this:
add_all = {'career_medicine': None, 'career_law': None, 'median_salary': None, 'mean_salary': 75000.0, 'career_business': 'operations / logistics', 'number': None, 'percent': 0.07}
An additional problem is that I do not know if the names will match, and I am looping through a list of add_sal and a list of add_perc.
Any advice would be appreciated!
Thank you in advance!
Posted on 16 Aug 2022, this text provides information on IoT Frameworks related to Internet of Things. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Take Quiz To Earn Credits!
Turn Your Knowledge into Earnings.