+ 1

I have two dictionary's convert into single dictionary with different keys and values,can anyone solve this one?

Two inputs: input_1 = [ { "pageId":"block", "pageTitle":"Title 1", "description":"description 1", "url":"some.s3.url" }, { "pageId":"warning", "pageTitle":"Title 2", "description":"description 2", "url":"some.s3.url" }, { "pageId":"security", "pageTitle":"Title 3", "description":"description 3", "url":"some.s3.url" } ] input_2 = { "block":{ "pageTitle":"Updated Title 1", "description":"Updated description 1", }, "warning":{ "pageTitle":"Updated Title 2", "description":"Updated description 2", }, "security":{ "pageTitle":"Updated Title 3", "description":"Updated description 3", } } This is the Output i want : output = [ { "pageId":"block", "pageTitle":"Updated Title 1", "description":"Updated description 1", "url":"some.s3.url" }, { "pageId":"warning", "pageTitle":"Updated Title 2", "description":"Updated description 2", "url":"some.s3.url" }, { "pageId":"security", "pageTitle":"Updated Title 3", "description":"Updated description 3", "url":"some.s3.url" } ]

11th Feb 2022, 6:20 AM
Manoj Bhaagam
4 Respostas
+ 4
Manoj Bhaagam , can you show us your attempt? i suppose that it is not to combine the 2 dictionary to a new ones, but we should use input_2 to update input_1. can you confirm this? may be the complete task description is a good help for us. thanks
11th Feb 2022, 1:47 PM
Lothar
Lothar - avatar
+ 1
# Hi! Here is one way to merge two dicts: d1 = {"a": 1 , "b": 2} d2 = {"c": 3 , "d": 4} merged_1 = {**d1, **d2} print(f"{merged_1} = ") # Caveat! It requires unique keys in d1 and d2, otherwise key values in d1 will be overwritten.
11th Feb 2022, 6:46 AM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Hi, Manoj Bhaagam. Here’s a solution you can check out: https://code.sololearn.com/cXojVz8rtKxI/?ref=app
11th Feb 2022, 4:02 PM
Per Bratthammar
Per Bratthammar - avatar
0
Hi Manoj! Since you declared input_1 as a list, you can add input_2 with input_1 using append() method input_1.append(input_2) print(input_1)
11th Feb 2022, 6:48 AM
Python Learner
Python Learner - avatar