Linked Questions

385 votes
5 answers
689k views

Say I have three dicts d1={1:2,3:4} d2={5:6,7:9} d3={10:8,13:22} How do I create a new d4 that combines these three dictionaries? i.e.: d4={1:2,3:4,5:6,7:9,10:8,13:22}
timy's user avatar
  • 3,943
238 votes
4 answers
168k views

How do you calculate the union of two dict objects in Python, where a (key, value) pair is present in the result iff key is in either dict (unless there are duplicates)? For example, the union of {'a'...
Mechanical snail's user avatar
51 votes
4 answers
125k views

I try to sum two dictionaries like that: my_new_dict = dict(my_existing_dict.items() + my_new_dict.items()) but recieve error TypeError: unsupported operand type(s) for +: 'dict_items' and '...
JohnDow's user avatar
  • 1,332
19 votes
3 answers
13k views

I have two dictionaries One: default = {"val1": 10, "val2": 20, "val3": 30, "val4": 40} Two: parsed = {"val1": 60, "val2": 50} Now, I want ...
Rohan Asokan's user avatar
52 votes
2 answers
7k views

I have a list which contains multiple JSON objects and I would like to combine those JSON objects into a single json object, I tried using jsonmerge but with no luck. My list is: t = [{'ComSMS': '...
user avatar
20 votes
5 answers
4k views

I have two dictionaries as follows: D1={'a':1,'b':2,'c':3} and D2={'b':2,'c':3,'d':1} I want to merge these two dictionaries and the result should be as follows: D3={'a':1,'b':2,'c':3,'b':2,'c':...
Pravitha V's user avatar
  • 3,308
30 votes
3 answers
6k views

Let's say I have a dictionary: x = {"x1":1,"x2":2,"x3":3} and I have another dictionary: y = {"y1":1,"y2":2,"y3":3} Is there any neat way to constract a 3rd dictionary from the previous two: z = {"...
Mero's user avatar
  • 1,350
28 votes
1 answer
5k views

I have two dictionaries that I want the union of so that each value from the first dictionary is kept and all the key:value pairs from the second dictionary is added to the new dictionary, without ...
NicolaiF's user avatar
  • 1,373
16 votes
3 answers
814 views

I was doing django project about processing request.data and from.cleaned_data issues. When user only inputs specify fields, it will send request to my server. Next, the form class process the request,...
Burger King's user avatar
  • 2,975
7 votes
3 answers
1k views

I have a problem with concatenating dictionaries. Have so much code so I show in example what my problem is. d1 = {'the':3, 'fine':4, 'word':2} + d2 = {'the':2, 'fine':4, 'word':1, 'knight':1, '...
MTG's user avatar
  • 301
20 votes
1 answer
2k views

I am new to python and have looked at other answers on merging dictionaries but was still a bit confused. I am looking to merge together two dictionaries in python by a common value within a specific ...
RCN's user avatar
  • 671
2 votes
2 answers
4k views

I am looking for feedback on my Python code. I am trying to merge two dictionaries. One of the dictionaries controls the structure and the default values, the second dictionary will overwrite the ...
Patrick's user avatar
  • 312
2 votes
1 answer
4k views

The question is This is what I have so far: dict(nafta_capitals) = canadian_capitals, mexican_capitals, us_capitals Given three dictionaries, associated with the variables , canadian_capitals, ...
Anthony Tesoriero's user avatar
1 vote
0 answers
3k views

Let's say I am given a nested dicionary my_dict and another nested dict update: a sequence of keys (valid in my_dict) with a value to be assigned to the leaf at this sequence. For example, my_dict = { ...
SBF's user avatar
  • 357
2 votes
2 answers
642 views

How can I print a dictionary as a union of given dictionaries & appending the values if the keys are equal? Input: dict_1 = { "x":[1,"hello"], "y":[2,"...
ChocoApplePiez's user avatar

15 30 50 per page
1
2 3 4 5
25