Easiest way to create a new filled dictionary

I try to create a new filled dictionary that looks like:
employee = {“name”:“George”, “age”:21, “nationality”:“Romanian”}

Is there an easier way to create it than this:

assign ->employee = new Dictionary(of String, String)
assign ->employee(“name”) = “George”
assign ->employee(“age”) = 21
assign ->employee(“nationality”) = “Romanian”

In Python you can do it like:

employee = {“name”:“George”, “age”:21, “nationality”:“Romanian”}

3 Likes

Hi @Victor_Stanescu

You can also use “Add to Dictionary” activity to add the Key and value in the Dictionary.
image

3 Likes

yah we can do that either in UiPath in a easier way
like in studio at the VARIABLE panel
give the name of the variable as dic_variable
and variable type as System.Collections.Generic.Dictionary(of string)(string) and to search this type we can click on Browse for types in variable type column in variable panel
then scope - set that to the whole sequence as a global variable
and in default value field mention as
New Dictionary(of string, string) from {{“key1”,“value1”},{“key2”,“value2”}}

and if we want to add them once after creating a dicitonary variable then we can use ADD TO DICTIONARY ACTIVITY OR With a simple assign activity like this
dic_variable(“your keyname”) = "your value"

hope this would help you
Cheers @Victor_Stanescu

8 Likes

Nice! I tested and it worked.

Thank you @Palaniyappan

1 Like

awesome
@Victor_Stanescu

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.