Changing a list to a Sublist in Python

Hello there everyone,

Could someone please help, as I am just learning about Python Script.
I am currently trying to split my list of points, created in an excel sheet, in to sublists. As you can see, I have already done so in Dynamo, but I am trying to do so in Python as well. Could you try and help me understand what I am missing.

Hello @tristanBSLV3 ,
Welcome to Dynamo Community,

you are creating the for loop in empty list (Sublist), So technically you code never enter inside the for loop and given you an output of empty list (Sublist)

So how do I fix this issue?
As I stated in my post, I am still learning Python Scripting, so I will not understand anything that I might miss.

Hello @tristanBSLV3 ,
As you mention, you have already done this task in Dynamo,
So can you please share that dynamo script, it will be easy for me to understand the actual working, inputs and outputs of the script, then i will try to do the same task using python.

Hi @tristanBSLV3

You can do this:

from itertools import islice

l = IN[0]
r = IN[1] if isinstance(IN[1],list) else [IN[1]]
o = IN[2]

def chunk(lst,_range,step):
	result = []
	for i in range(0,len(lst),step):
	return result

OUT = chunk(l,r,o)

And don’t forget that you can use DSCore library in Python, so you could use the same node as well.

1 Like

Example with a python iterator

import clr
import sys
iterNbr = iter(IN[0])
OUT = [[i,j] for i, j in zip(iterNbr, iterNbr)]

thanks, it helped.