How to append one dictionary to another

Hi,

I have two dictionaries Config 1 and Config 2.

I’m trying to append Config 2 to Config 1, I found c# code in online

dictionaryFrom.ToList().ForEach(x => dictionaryTo.Add(x.Key, x.Value));

how can I implement this in UIPath

Thanks in advance.

1 Like

You can use For Each Activity to append the dictionary.

Set item type to dictionary object in the properties panel.

For Each item in Dictionary2
       Dictionary1.Add(item.Key,item.Value)

Hi,
use an assign activity then try the following code,
dictionaryFrom.ToList().ForEach(Function(x) dictionaryTo.Add(x.Key, x.Value))

2 Likes

Capture1

Capture2

But It’s not returning any value We can’t use Assign activity here.

dictionary1.Union(dictionary2).ToDictionary(Function (k) k.Key, function(v) v.Value)

I am combining both dictionary and put all values into dictionary1 inside an assign activity.

1 Like

PEP 448 also expanded the abilities of ** by allowing this operator to be used for dumping key/value pairs from one dictionary into a new dictionary . Leveraging dictionary comprehension and the unpacking operator, you can merge the two dictionaries in a single expression .

dict1 = {1:‘one’ , 2:‘two’}
dict2 = {3:‘three’, 4:‘four’}
fDict = {**dict1 , **dict2}
print(fDict)
{1: ‘one’, 2: ‘two’, 3: ‘three’, 4: ‘four’}