Shorten a list to be equal to another list

Hi All,
In my example below I want to remove elements from lst2 to have (lst2 length) = (lst1 length)
so how to do that in python?

Thanks.

Hello, here is a way

# Charger les bibliothèques DesignScript et Standard Python
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Les entrées effectuées dans ce noeud sont stockées sous forme de liste dans les variables IN.
lst_1=IN[0]
lst_2=IN[1]
new_lst_2=[]

# Placer votre code au-dessous de cette ligne
for i in range(0,len(lst_1)):
    item=lst_2[i]
    new_lst_2.append(item)
# Affectez la sortie Ă  la variable OUT.
OUT = new_lst_2

edit : another possibility

# Charger les bibliothèques DesignScript et Standard Python
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Les entrées effectuées dans ce noeud sont stockées sous forme de liste dans les variables IN.
lst_1=IN[0]
lst_2=IN[1]


# Placer votre code au-dessous de cette ligne
new2_lst_2=lst_2[0:len(lst_1)]
# Affectez la sortie Ă  la variable OUT.
OUT = new2_lst_2

cordially
christian.stan

3 Likes

Thanks @christian.stan it’s so easy !! :roll_eyes:

1 Like

I am learning (personally) python with this site
more analysis of the scripts of Mr. _. _o_p_n and other members from here

Don’t be discouraged

when it comes to teasing the api I would buy a German book (Mr. Draxl talked about it) translated into English (recommended on this site)
cordially
christian.stan

1 Like

What about List.Count and List.TakeItems?

1 Like

@Daan
Can you give me an example?
Thanks.

Hi, I still like designscript :wink:


code block: L2_new=L2[0..DSCore.List.Count(L1)-1];

edit:
a little shorter


code block: L1@L1*L2/L1@L1;
Autruche GIFs | Tenor
only for numbers
good evening

cordially
christian.stan

1 Like