Shift nested List in Python

Hello community,

I’m learning now Python for GH since 3 month but get stuck in topic nested Lists. As seen in the picture I have a surface which is divided in U and V and using the given Points in the Python script. I try to shift the nested list everytime for 1 step and then connect the output points with a polyline. But somehow the desired function doesn’t come out :man_facepalming:. Does anyone has an idea what could be my problem?

Thank you for help. Gh is attached.

import Rhino
import Grasshopper.DataTree as ghdt

newTree = ghdt[object]()
branchN = ptsTree.BranchCount # V - Value
itemN = ptsTree.DataCount # all Items U * V
itemPerBranch = int(itemN/branchN) # U - Value

# convert input data tree to python list of lists
listOfLists = []
for i in range(branchN):

# change on listOfLists data

modList = []
for i in range(0,len(listOfLists)-1):
    for j in range(0,itemPerBranch):

a = modList

Shift (11.4 KB)

I added a list shifting section, and made two minor changes to your script:

Adapted GH: Shift (14.4 KB)

You’ll want to figure out a way to not connect the end points of the separate lists.

Thank you! Helps already to understand more where the bug was :slight_smile:

Small side note: the Python deque is really neat for cases where you need to shift lists (using its rotate method):

Though in this case it may be a bit overkill

1 Like