What is being described it seems is carrying out a for loop within a for loop. I agree with @Nick_Boyts, this could be easily achieved by changing the lacing of the node being input.
But in python terms to access a nested list (this is assuming a 2 level list) would be :
for i in items:
for j in i:
do_something()
this is saying for each item in the top list [i] … then for every item within this list [j]…
think…
i[0],j[0]
i[0],j[1]
i[1],j[0]
i[1],j[1]
i[2],j[0]
i[2],j[1]
This will only work for a two-level list, if you want to access the most nested items you would need to look into a recursive function which tests for list lengths until you are down to single items.
Without looking too much into the code … from a brief glance it seems you would want to change
ids = list()
rejects = list()
for item in items:
try:
ids.append(item.Id)
except:
rejects.append(item)
items = List[ElementId](ids)
to
ids = [] # this is shorthand for a list
rejects = []
for sub_list in items: # this will iterate through the top list
for item in sub_list: # this will iterate through all items within the top lists
try:
ids.append(item.Id)
except:
rejects.append(item)
items = List[ElementId](ids)
Hope this helps / makes sense
(I’m slightly to dubious as to how good a name sublist is here for a variable, but hopefully it serves to illustrate the point)