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 do I join these different dictionary in a single variable to one single dictionary

Convert Function:

def Convert(a):
    it = iter(a)
    res_dct = dict(zip(it, it))
    return res_dct

w=0

r=0

u={}


for q in lit:

    w=(list(q))

    r=Convert(w)


    for key, value in r.items():

        r[key] = value
   
 print(r)

Output:

{'chapter': 56} {'i': 2597} {'emma': 719} {'woodhouse': 249} {'handsome': 30} 
{'clever': 24} {'and': 4534} {'rich': 14} {'with': 1244} {'a': 3101} 
{'comfortable': 34} {'home': 112} {'happy': 116} {'disposition': 23} 
{'seemed': 139} {'to': 5202} {'unite': 3} {'some': 260} {'of': 4363} 
{'the': 5271} 

I need These outputs in a Single Dictionary

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

Initially The lit is a list containing the list of output

>Solution :

lit = [{'chapter': 56},
   {'i': 2597},
   {'emma': 719},
   {'woodhouse': 249} ,
   {'handsome': 30},
   {'clever': 24} ,
   {'and': 4534},
   {'rich': 14} ,
   {'with': 1244} ,
   {'a': 3101} ,
   {'comfortable': 34},
   {'home': 112},
   {'happy': 116},
   {'disposition': 23} ,
   {'seemed': 139} ,
   {'to': 5202},
   {'unite': 3},
   {'some': 260},
   {'of': 4363} ,
   {'the': 5271}]
res = {}

for i in lit:
    for k in i:
        res[k] = i[k]

print(res)
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