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

Turn dictionary values into an array python

I named it dict1, for example, but in fact I use a dictionary from the Internet, which I can’t rewrite initially.The values are set.

dict1 = {'cats':{'1','2'},
        'dogs':{'1'}}

Output:

{'cats': {'1', '2'}, 'dogs': {'1'}}

I want the values to be an array, not a dictionary. Output i want:

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

{'cats': ['1', '2'], 'dogs': ['1']}

>Solution :

You can do:

dict2 = {k: list(v) for k, v in dict1.items()} 
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