# Copy/match list structure

**URL:** <https://forum.dynamobim.com/t/copy-match-list-structure/68951>\
**Category:** Lists-Logic\
**Tags:** dynamo\
**Created:** [October 6, 2021, 11:00am UTC](https://forum.dynamobim.com/t/copy-match-list-structure/68951 "2021-10-06T11:00:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![CarlC](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/carlc/32/124593_2.png) [@CarlC](https://forum.dynamobim.com/u/CarlC)\
**Post date:** [October 6, 2021, 11:00am UTC](https://forum.dynamobim.com/t/copy-match-list-structure/68951/1 "2021-10-06T11:00:46Z")

</div>

Hi all,

I want to rearrange a flattened list into a specific sublist arrangement. I tought this would be easy-peasy but its driving me insane. What am I missing?

 ![matchlistorder](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/5/45dd7ae941b5f68c15adfc79535ab500f76a2310.png)

In this example I want to arrange the letters in the sublist to match the order of the numbers, but it really applies to any flattened list with any kind of data, the same length as a non flattened list.

---

<div class="post-metadata">

**Author:** ![honeyjain619](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/honeyjain619/32/121215_2.png) [@honeyjain619](https://forum.dynamobim.com/u/honeyjain619)\
**Post date:** [October 6, 2021, 11:24am UTC](https://forum.dynamobim.com/t/copy-match-list-structure/68951/2 "2021-10-06T11:24:21Z")

</div>

Hello @CarlC

I know its a lacing problem, but i dont know how to solve using dynamo nodes,  
but it can be solved using python

[Copymatch list.dyn](https://forum.dynamobim.com/uploads/short-url/rVt1iwbLn5y5fRZzy5VqeAcudmU.dyn) (13.9 KB)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/c/8cb67c1072cda444ab8fc05e7e6830673efeb5e0.png)

---

<div class="post-metadata">

**Author:** ![CarlC](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/carlc/32/124593_2.png) [@CarlC](https://forum.dynamobim.com/u/CarlC)\
**Post date:** [October 6, 2021, 11:33am UTC](https://forum.dynamobim.com/t/copy-match-list-structure/68951/3 "2021-10-06T11:33:00Z")

</div>

Hi @honeyjain619

I see, seems a bit complicated! And there are two python scripts because right now the nesting go two levels deep I guess? How to achieve something more dynamic, independent of the number of nested levels, is really what I’m trying to figure out.

---

<div class="post-metadata">

**Author:** ![CarlC](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/carlc/32/124593_2.png) [@CarlC](https://forum.dynamobim.com/u/CarlC)\
**Post date:** [October 6, 2021, 1:20pm UTC](https://forum.dynamobim.com/t/copy-match-list-structure/68951/4 "2021-10-06T13:20:04Z")

</div>

Allright, I found a working OOTB solution! Using add item to front and then take items. Not the most obvious solution imho…

 ![matchlistorder_3](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/4/b4ff62eb388ceb299272a77bd61f1daa1e29794e.png)

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [October 6, 2021, 3:50pm UTC](https://forum.dynamobim.com/t/copy-match-list-structure/68951/5 "2021-10-06T15:50:17Z")

</div>

While it is always better to retain the List Structure (where required) through the intermediate steps, you could something like this to restructure a list.  
I wouldn’t encourage this approach though 😏

 ![reconstructStructure_2021-10-06_09-07-17](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/0/20a2c76be92529a888b975f254c5a7ee52c90e8a.png)

[reconstructStructure.dyn](https://forum.dynamobim.com/uploads/short-url/uqrArgdrqWIW3Gu92CH15QWzxJy.dyn) (11.2 KB)

```auto
def reconstruct (lst01:var[]..[],lst02:var[]..[])
{
	cnt01 = List.Count(List.Flatten(lst01<1>,-1)<1>);
	cnt02 = List.Count(List.Flatten(lst01<1><2>,-1)<1><2>);
	cnt03 = List.Count(List.Flatten(lst01<1><2><3>,-1)<1><2><3>);
	cnt04 = List.Count(List.Flatten(lst01<1><2><3><4>,-1)<1><2><3><4>);
	cnt05 = List.Count(List.Flatten(lst01<1><2><3><4><5>,-1)<1><2><3><4><5>);

	chp01 = List.Chop(lst02,cnt01);
	chp02 = List.Chop(chp01<1>,cnt02<1>);
	chp03 = List.Chop(chp02<1><2>,cnt03<1><2>);
	chp04 = List.Chop(chp03<1><2><3>,cnt04<1><2><3>);
	chp05 = List.Chop(chp04<1><2><3><4>,cnt05<1><2><3><4>);

	ind01 = List.Flatten([cnt01,cnt02,cnt03,cnt04,cnt05]<1>,-1);
	ind02 = List.IndexOf(List.AllTrue((ind01==1)<1>),true)-1;

	return List.GetItemAtIndex([chp01,chp02,chp03,chp04,chp05],ind02);
};

```

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [October 6, 2021, 5:06pm UTC](https://forum.dynamobim.com/t/copy-match-list-structure/68951/6 "2021-10-06T17:06:08Z")

</div>

It’s messy but it does what you need. I believe this will work on any structure as well.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/5/b59977dcdf2a837ee88a07c04418fda3fd663e65.png)

---

<div class="post-metadata">

**Author:** ![CarlC](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/carlc/32/124593_2.png) [@CarlC](https://forum.dynamobim.com/u/CarlC)\
**Post date:** [October 7, 2021, 9:36am UTC](https://forum.dynamobim.com/t/copy-match-list-structure/68951/7 "2021-10-07T09:36:42Z")

</div>

Nice, seems not as messy as mine at least 🙂
