简体   繁体   中英

How append multiple dicto into a one dict python

I develop with python and i have a multiple dictionnary like:

Dict1: {‘hi’:’340’, ‘hello’:’570’, ’me’:´800’}
Dict1: {‘hi’:’200’, ‘hello’:’100’, ’me’:´389’}

And i would like to add them together into a dict like:

Dict_new= { {‘hi’:’340’,‘hello’:’570’, ’me’:´800’},     {‘hi’:’200’, ‘hello’:’100’, ’me’:´389’}} 

Finally i would likt to have this output:

 {‘elements’:{{‘hi’:’340’,‘hello’:’570’, 
                    ’me’:´800’},
                 {‘hi’:’200’, ‘hello’:’100’, 
                ’me’:´389’}}}

So what is the best mannee to do this?

Instead of using a set , please consider using a list which will store your dictionaries.

newDict = {}
newDict['element'] = [dict1,dict2]

output

{'elements': [{'hi': '340', 'hello': '570', 'me': '800'}, {'hi': '200', 'hello': '100', 'me': '389'}]}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM