Matching 2 sublists

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?

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?

1 Like

hi robertoruggeri
try this out

have a good day

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.


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

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

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])
OUT = l1

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

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)
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?

1 Like

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

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

nest.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.

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

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)
OUT = L1

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:

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

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.

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?


You can associate a parameter to drive what text is being displayed. See here.

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

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).

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.

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

1 Like

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?