Greetings,
In my project I want the following arrays to be merged into a single dictionary with a key pair value of {array1,array2}
array1 = (“1”,“2”,“3”,“4”)
array2 = (“One”, “Two”, “Three”, “Four”)
What is the best approach to combine the two arrays?
Hi @tom_mccaffrey ,
We could Merge the two Arrays in to a Key Value Pair Dictionary type provided both the arrays have equal number of items in it. We can use the Expression below in an Assign
Activity :
dictFromArrays = Enumerable.Range(0, numberList.Length).ToDictionary(Function(i)numberList(i),Function(i)wordsList(i))
Here, dictFromArrays
is a Dictionary(Of String,String) type variable, numberList
and wordsList
are two Array of String type variables.
1 Like
ppr
(Peter Preuss)
June 3, 2022, 2:12pm
3
we assume that the arrays are reliable of the same length
dictVar =
Enumerable.Range(0,array1.Length).toDictionary(Function (x) array1(x), Function (x) array2(x))
as an variation we also can do
array1.Select(Function (x,i) i).toDictionary(Function (x) array1(x), Function (x) array2(x))
2 Likes
Peter with the answer as always, appreciate it!
If you want the simple way to do it…
ppr
(Peter Preuss)
June 3, 2022, 2:35pm
6
Thank you for the feedback.
@supermanPunch 's approach is using a similar idea. He just used other variable names. May I ask you flag his answer as solution in case you did not use my secoond presented option. Thank You.
1 Like
system
(system)
Closed
June 6, 2022, 2:36pm
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.