# Matching 2 sublists

**URL:** <https://forum.dynamobim.com/t/matching-2-sublists/34816>\
**Category:** Lists-Logic\
**Created:** [April 14, 2019, 9:35pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816 "2019-04-14T21:35:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertoruggeri](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@robertoruggeri](https://forum.dynamobim.com/u/robertoruggeri)\
**Post date:** [April 14, 2019, 9:36pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/1 "2019-04-14T21:36:00Z")

</div>

Hi, I have a list made by sublists and I would like to match some items with another list.  
Attached an example. Could somebody help me?

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

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [April 15, 2019, 12:59am UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/2 "2019-04-15T00:59:33Z")

</div>

Take Last Items of list 2 using List.LastItem node with lacing set to longest and then use Add.ItemsToEnd node with lacing to longest to add items at the end of each Sub List. Hope this what you want to achieve?

---

<div class="post-metadata">

**Author:** ![dineshsubramani](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dineshsubramani/32/159417_2.png) [@dineshsubramani](https://forum.dynamobim.com/u/dineshsubramani)\
**Post date:** [April 15, 2019, 2:34am UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/3 "2019-04-15T02:34:58Z")

</div>

hi robertoruggeri  
try this out

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/f/7f2a637dcd46a98f4b95cb8effc11e4222f1a68a.png)  
have a good day

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [April 15, 2019, 2:41am UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/4 "2019-04-15T02:41:49Z")

</div>

Hello @dineshsubramani. Thanks for your attempt but unfortunately, that isn’t what he is asking for. He wants to add the item in List 2 to the matching list in List 1. Yours just puts the item into any list.

For example, the list at the bottom, `[[1, -138.82], [5, -138.9]]`, the second list has 5 in the first index so he wants the `-138.9` attached to the list in List 1 with `5` at index 0. Yours just adds it directly into the next list that happens to have `2` at index 0.

---

<div class="post-metadata">

**Author:** ![robertoruggeri](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@robertoruggeri](https://forum.dynamobim.com/u/robertoruggeri)\
**Post date:** [April 15, 2019, 6:32am UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/5 "2019-04-15T06:32:41Z")

</div>

Hi @dineshsubramani thank you for your attempt but as @kennyb6 said this is not what I was looking for. I want something like if the value is at list X in position 1 you can punt the second value at the end of that list. @kennyb6 saw what I mean

---

<div class="post-metadata">

**Author:** ![robertoruggeri](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@robertoruggeri](https://forum.dynamobim.com/u/robertoruggeri)\
**Post date:** [April 15, 2019, 6:37am UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/6 "2019-04-15T06:37:15Z")

</div>

Hi @Kulkul unfortunately this is not what i was looking for. See what @kennyb6 said to @dineshsubramani to see what I meant.

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [April 15, 2019, 6:54am UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/7 "2019-04-15T06:54:30Z")

</div>

I can’t test it right now for you but this should work in a python node, as long as that is your specific list structure:

```
l1 = IN[0] #list 1
l2 = IN[1] #list 2
for _l2 in l2:
    i = [l[0] for l in l1].index(_l2[0])
    l1[i].append(_l2[1])
OUT = l1
```

---

<div class="post-metadata">

**Author:** ![robertoruggeri](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@robertoruggeri](https://forum.dynamobim.com/u/robertoruggeri)\
**Post date:** [April 15, 2019, 6:03pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/8 "2019-04-15T18:03:45Z")

</div>

Hi @kennyb6 unfortunately it is now working, maybe some typos but I don’t know what

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [April 15, 2019, 11:34pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/10 "2019-04-15T23:34:56Z")

</div>

Slight modification to @kennyb6’s work:

```
L1 = IN[0]
L2 = IN[1]
L1_inds = [sublist[0] for sublist in L1]
for L2_sublist in L2:
    L2_ind = L2_sublist[0]
    if L2_ind in L1_inds: # Only proceed if matching index is found
        L2_val = L2_sublist[1]
        i = L1_inds.index(L2_ind)
        L1[i].append(L2_val)
OUT = L1

```

This will only create the list of first items in L1 once (rather than recreate it every loop) and will also only call list.index() if the index from L2 is actually in L1 (which would otherwise throw an exception). Would you be able to provide additional screenshots of what isn’t working?

---

<div class="post-metadata">

**Author:** ![robertoruggeri](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@robertoruggeri](https://forum.dynamobim.com/u/robertoruggeri)\
**Post date:** [April 23, 2019, 4:01pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/11 "2019-04-23T16:01:35Z")

</div>

Hi @cgartland, nothing happens. The result is the list L1 without any addition from list L2. How is it possible?

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [April 23, 2019, 4:15pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/12 "2019-04-23T16:15:20Z")

</div>

Sorry, your list is actually nested an additional level which I didn’t notice at first.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/3/530b0e7425df873c427d28fee0be9ceb79d358f2.png)  
[nest.dyn](https://forum.dynamobim.com/uploads/short-url/u1vFE4vRpDyHn04eevziEIwT8om.dyn) (4.9 KB)

I made my own lists and hard coded index 0 into the L1\_inds variable, so this will have to be modified to actually work with your full data set, but it should provide a sufficient starting point.

---

<div class="post-metadata">

**Author:** ![robertoruggeri](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@robertoruggeri](https://forum.dynamobim.com/u/robertoruggeri)\
**Post date:** [April 23, 2019, 8:02pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/13 "2019-04-23T20:02:40Z")

</div>

Hi @cgartland thanks a lot. Unfortunately your file is corrupted. could you upload it again?

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [April 23, 2019, 8:32pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/14 "2019-04-23T20:32:36Z")

</div>

Which version of Dynamo are you using? This is made using 2.0. Here is the text from the python node:

```
L1 = IN[0]
L2 = IN[1]
L1_inds = [sublist[0] for sublist in L1[0]]
    for L2_sublist in L2:
        L2_ind = L2_sublist[0]
        if L2_ind in L1_inds: # Only proceed if matching index is found
            L2_val = L2_sublist[1]
            i = L1_inds.index(L2_ind)
            L1[0][i].append(L2_val)
OUT = L1
```

---

<div class="post-metadata">

**Author:** ![robertoruggeri](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@robertoruggeri](https://forum.dynamobim.com/u/robertoruggeri)\
**Post date:** [April 23, 2019, 10:17pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/15 "2019-04-23T22:17:35Z")

</div>

Hi @cgartland thank you, now it works!! I used version 1.8…!  
Do you know if it’s possible to use the list to write points and text to bake on Revit?  
For example if you take 0 List you created:  
1  
0  
0  
0  
-138.82

Is it possible to write a text equal to “-138.82” at coordinate 0,0,0 in Revit ?

Same for 1List  
writing -138.9 at coordinate 5.5,0,0

Thanks in advance for your help! I am not an expert on using list on Dynamo in this way

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [April 23, 2019, 11:56pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/16 "2019-04-23T23:56:52Z")

</div>

That may be more difficult than it would first appear. My gut reaction would be to create model text, although the API specifies that it is specifically meant for use with Revit Families. However, you may be able to create a custom family which has a parameter driving the text being displayed in the family. If you set it up in this way, you can place a family instance by coordinates and set the custom parameter value (which will, in turn, change the text) to your desired value.

---

<div class="post-metadata">

**Author:** ![robertoruggeri](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@robertoruggeri](https://forum.dynamobim.com/u/robertoruggeri)\
**Post date:** [April 24, 2019, 11:34am UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/17 "2019-04-24T11:34:11Z")

</div>

Hi @cgartland thank you for your reply. What is not clear to me regarding your message is how to create “a parameter driving the text”. I don’t know how I could do it. (Family ok, family instance ok but how to insert a dynamic text?)  
Anyway I’ve tried to use the “TextNote.Bylocation” and I am quite close to the solution. Now my big issue is that I created a string with all the values I want to print but they are printed on each coordinate point xyz while I want a sort of “for” cycle where for each point xyz already ordered, it puts the n\_text of the array (already ordered too). It’s not a problem to have “Empty list” printed, I think it could be substituted easily. Do you know if it’s something possible to do?  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/2/229308ee186c59538d7217fe0978e608431bd6c7.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/b/8bbe29bd9553b3eb0058f47d042684412f71afe0.png)

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [April 24, 2019, 12:32pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/18 "2019-04-24T12:32:06Z")

</div>

You can associate a parameter to drive what text is being displayed. See [here](https://www.youtube.com/watch?v=H5m8kdTtW-I).

---

<div class="post-metadata">

**Author:** ![robertoruggeri](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@robertoruggeri](https://forum.dynamobim.com/u/robertoruggeri)\
**Post date:** [April 24, 2019, 1:30pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/19 "2019-04-24T13:30:27Z")

</div>

> [@cgartland](#):
>
> If you set it up in this way, you can place a family instance by coordinates and set the custom parameter value (which will, in turn, change the text) to your desired value.

Ok but when I place a family instance by coordinates, how can I set the custom parameter value (which will, in turn, change the text) to my desired value?  
The family instance needs xyz coordinates and the family…I don’t see how to “control” the parameter value

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [April 25, 2019, 2:13am UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/20 "2019-04-25T02:13:07Z")

</div>

So when you create the family that you want the text in, insert the text as a symbol using the Label Annotation (usually M\_Label Annotation.rfa or a variant of). This label will have a parameter that you can associate with the family’s type parameter.

After importing and placing the label annotation, open up the family’s parameter and create a new parameter with type set to Text and the parameter set to Instance (or Type if that is what you prefer).

 ![labeltext1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/5/d5fc3794c5807a32a8929c340a076a247b615b48.png)

Then click on the label you placed in the family and click Edit Type in the properties browser. Where it says Label, click the button on the far right and set it to the parameter you created.

 ![labeltext2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/5/2599fab8ac6978b463c4d9c7d443ed37b3149307.png)

Now you have a family with text that is set to a parameter, and you can control that parameter in Dynamo.

---

<div class="post-metadata">

**Author:** ![robertoruggeri](https://avatars.discourse-cdn.com/v4/letter/r/58956e/32.png) [@robertoruggeri](https://forum.dynamobim.com/u/robertoruggeri)\
**Post date:** [April 29, 2019, 9:31pm UTC](https://forum.dynamobim.com/t/matching-2-sublists/34816/21 "2019-04-29T21:31:51Z")

</div>

Hi @kennyb6 and @cgartland first of all thanks for your help. I’ve learnt a lot thanks to you. Now I’ve created the family with text that is set to a parameter and I am wondering how I can control my list printing the text In Dynamo. Is there a particular node to print a list using a family text?

[Next page](https://forum.dynamobim.com/t/matching-2-sublists/34816.md?page=2)
