Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python "Explode" Keys in Dict

Given a dict like the one below how do I "explode" the keys to create a new dict with the keys split out? Each key should be split on " n ".

original_dict = {"AB n DC": [12, 13], "JH n UY": [22, 1]}

new_dict = {"AB": [12, 13], "DC": [12, 13], "JH": [22, 1], "UY":[22,1]}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

new_dict = {k: v for orig_k, v in original_dict.items() for k in orig_k.split(' n ')}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading