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

how to convert dictionary of array to list and as key value in python

i have a dictionary with key value but values are in array,
i want to convert the array into value for each keys

#this is my dictionay
input_dic = {
    'pm_25': [22.5, 23.8, 24.9], 
    'pm_10': [2.76, 6.76, 2.76], 
    'humidity': [55, 10, 85], 
    'temprature': [12.7, 41.1, 85.1]
    }
# i want like this 
    want_to = [
        {'pm_25': 22.5, 'pm_10': 2.76, 'humidity': 55, 'temprature': 12.7},
        {'pm_25': 23.8, 'pm_10': 6.76, 'humidity': 10, 'temprature': 41.1},
        {'pm_25': 24.9, 'pm_10': 2.76, 'humidity': 85, 'temprature': 85.1},
    ]

please any one know how to convert this

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

>Solution :

[dict(zip(input_dic, values))
 for values in zip(*input_dic.values())]
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