Hi, guys.
I’m trying to get items except first and last and keep the structure of the list
But I think I missed lacing or level settings, please give me any advices
Hi @jaeho
I’ve made a python script which removes the first and last element in a list. It doesn’t keep the structure owned by the input list. It returns only elements contained in a list if the length of the list is bigger than two.
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
input_list = IN[0]
output_list = []
def remove_fist_last_item(input_list):
if any(isinstance(item, list) for item in input_list):
for item in input_list:
if isinstance(item, list):
remove_fist_last_item(item)
else:
if len(input_list) > 2:
output_list.append(input_list[1:-1])
remove_fist_last_item(input_list)
OUT = output_list
3 Likes
@Meychik @Mark.Ackerley Hi, Thank you for your solutions the problem is both approaches don’t keep the Empty List…
1 Like
It seems to work as you wanted it to be.
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
input_list = IN[0]
lst = [1,2,3,4]
def remove_first_last_items(input_list):
if any(isinstance(item, list) for item in input_list):
for item in input_list:
if isinstance(item, list):
remove_first_last_items(item)
else:
if len(input_list) > 2:
input_list.pop(0)
input_list.pop(-1)
remove_first_last_items(input_list)
OUT = input_list
2 Likes
Hi, Thank you so much for your solution. Can I ask one more?
Is it possilbe flatten these hightlighted items??
Hi@Meychik,
Thank you for your solution again!
1 Like
Hello,
a node version
Cordially
christian.stan
2 Likes
@christian.stan Thank you for your solution. I haven’t thought about the codeblock like that for amount. Good approach
1 Like