How to put data of two lists in one list

Hi everyone,

I’ve 2lists as below:
list1 = (“1”,“2”,“3”,“4”…)
list2 = (“120”,“130”,“140”,“150”…)

I need to store this value in final list as
FullList =(1,120,2,130,3,140…)

Please tell me how to join these two dynamic lists in one final list.

Thank You

@siddhi.rani

FullList = list1.Union(list2).ToList()

Hope this may help you

Thanks,
Srini

@siddhi.rani

FullList = list1.Union(list2).ToList()

FullList is a new List you can initialize

Thanks,
Srini

You can iterate through one of the list and use the same index to add the items from both the list using the Append Item to List activity. So iterate through list 1 and keep adding item 1 from list 1 and item 1 from list 2 ( using the same index of 1) and so on…

1 Like

@siddhi.rani

Also you can try as below

FullList = list1.Concat(list2).ToList()

The above is merging without checking for duplicates

FullList = list1.Union(list2).ToList()

Above will check the duplicates and make into one list

Hope these may help you

Thanks,
Srini

2 Likes

Hi @siddhi.rani ,

L1.concat(L2).tolist

Regards

@siddhi.rani

Declare the two lists that you want to combine

list1 = {“a”, “b”, “c”}
list2 = {“d”, “e”, “f”}

Use the Concat method to combine the two lists into a new list

combinedList = list1.Concat(list2).ToList()

Hi,

if it’s unnecessary to take care result order, the following works.

list1.Concat(list2).ToList

If it’s necessary to alternate each items of list1 and list2, the following will help you.

Case of count of list1 is same count of list2

list1.Zip(list2,Function(s1,s2) {s1,s2}).SelectMany(Function(a) a).ToList

Case of count of list1 is more than count of list2

list1.SelectMany(Function(s,i) if(i<list2.Count,{s,list2(i)},{s})).ToList

Case of count of list1 is less than count of list2

list2.SelectMany(Function(s,i) if(i<list1.Count,{list1(i),s},{s})).ToList

Regards,

2 Likes

Thanks everyone for the help.

@Yoichi, your solution for 2nd Case to store alternate values, worked for me.

Thanks.

1 Like

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