Python Get every first item of sublist

Hi, I am very new to python. I have a sublist to level 3. How can I take every first item from the sublist? I want to do it in python… thank you.

Hi @newshunhk

So, something like this? But in Python?

Look into python for loops. Depending on your list structure, it just becomes a single loop or nested loops to get to the level you’re after.

@newshunhk try this:

# Load the Python Standard and DesignScript Libraries
import sys
import clr
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
lists= IN[0]
listOfList = [lists]
# Place your code below this line
list1 = [item[0] for item in lists]
list2 = [item[0] for item in lists for lists in listOfList]
# Assign your output to the OUT variable.
OUT = list1, list2

Thanks tradelie!
I didnt realize I can use for loop in that simple way!
Thanks all for the replies above too!! :grinning:

1 Like