Matching sublist elements sequentially

Hi all,

Struggling with lists again, is there a way to match these lists with sublists in the following way?:

List
0 List
[0] RV1 insertar descripcion
[1] null
[2] null
[3] RV2 insertar descripcion
[4] null
[5] null
[6] RV3 insertar descripción
[7] null
[8] null
[9] null
1 List
[0] RV1 insertar descripcion

Probably with some programming it would be fairly easy, but I lack of those skills. Any help will be much appreciated!

(Description of what I want to achieve, but I think it´s much better the graphical descpription)
If item in first sublist is not empty, match it with the first element of the first item of the sublist contained in the second list. If the next element is null, skip it until next no empty item and match with the second element of the second sublist. I mean, The new list would look like this:

The if node could be what you are looking for:
http://dynamoprimer.com/en/04_The-Building-Blocks-of-Programs/4-3_logic.html

Note: You will need to use the search field and all available resources, and try what’s possible before asking for python skills :slightly_smiling_face:

1 Like

@DyNewby

I mead a example for you. I think this is what want to do.

I hope I helped you.

1 Like

Hi again @Yna_Db, I know it looked I haven´t done my homework, but I honestly couldn´t figure it out, I was always running into the same issue, the prefix was following the index and going up! I can´t get ride of the null values because I would like to keep the spaces in the excel table I want to create.

imagen

@NLDaniel, thank you so much! But I was looking for a little twist to it, the rv1,2,3…shouldn´t skip numbers, in your first sublist the sequence I wanted is:

[0] rv1 Insertar Descreipcion
[1] null
[2] rv2 Insertar Descreipcion
[3] null
[4] rv3 Insertar Descreipcion
[5] null

It seems that the OOTB nodes can’t do this easily. These ones could help:

1 Like

@DyNewby

I see what i did wrong, my bad. But i made a python script for you. I think this is the best way.

1 Like

Thanks again @Yna_Db! Well, I have tried some attempts to adapt your reasoning, but if you don´t mind, can I ask what would be your approach to deal with sublists? I have tried flatten it but it is not working as it keeps numbering sequentially, and getting every item at index option sounds good to me, but surely it must a better way to do it.


imagen

Much appreciated!

Thank you soooooooooo much @NLDaniel! No words for such a neat solution! Love it!

If you have another minute to spare, would you be so kind to tell me what am I doing wrong? Not sure what you connected to c, but I´m not getting the same results.

You will need to use List@Level for that, please see here how this works:
http://dynamoprimer.com/en/06_Designing-with-Lists/6-3_lists-of-lists.html
The Dynamo Primer is a useful resource in many cases, but for now:

1 Like

Oh, I´m so sorry to make a fantastic user not complain with the guidelines, but I´m so sure he did it with the best of intentions in mind. I´m definitely not an advanced user, not even an intermediate one, but after seeing tons of examples I could guess some approaches, and it looked like that with the standard nodes it was a hefty task so I asked for help. I´m more than willing to learn, any approach is welcomed and surely I will start to learn coding. Sorry if my question induced to break the rules.

1 Like

Thanks again for your help!

@DyNewby

Your welcome. the c input was just a space so the words wont connect. Wy this fails is because your input in IN[1] is a list of 60 items. You only need your 10 items. So the input should be a flatten list with:
1 RV1 Insertar Descreipcion
2 RV2 Insertar Descreipicion
4 RV3 Insertar Descreipcion
5 RV4 Insertar Descreipicion
and on

see picture
I olso removed the c for future confucions.
I will atach the file as whele so you can see how it works. It is made in dynamo version 1.3.1

Home.dyn (14.9 KB)

1 Like

I can´t thank you enough for your time, worked like a charm! Love it!
And just changed “null” in line 22 to resultlist.append(None) (it was returning null in my schedule). I´ve just started programming :joy: and I´m feeling this is the best day of my week!

1 Like

@Yna_Db, if you don´t mind, can you take a look at this? I don´t know if this is a funny behaviour or I just doing something wrong (tried to find documentation about it and not much about this came out):

If the number of items in the b list is the same than the a list, the result is the desired. But if the number is different, it starts to behave oddly as you can see:


Sometimes even if contains the same number it doesn´t return the right result:

In the first case, it looks like a normal behaviour, nothing to worry about. What would you need for a result if the lists lengths don’t match: repeat the last item, leave it blank, … ?

In the second case, I have to look further

Yep, the first example is the result I was expecting. I think if the lists length don´t match, the Code Block does a good job using the short lacing but the problem comes with the List.ReplaceItemAtIndex that replaces randomly the values and I´m not sure why.

Thanks a lot for looking at it

This should help:


Don’t take into acount the Flatten nodes, I just used them to reproduce your situation.
Basically, what I have changed is “chopping” the list of items used for replacement and set the level of this input at @L2. It is possible that you need to play a little with levels but this is important to learn anyway: most of the time when recomposing lists, we need to test different configurations before it works.

Great! Thanks again for your input @Yna_Db , it´s been really helpful.
Well, that´s for sure, learning is the goal and there is no better way than learning by doing, so I will spend tomorrow tinkering it!