Keep list structure empty

I’m trying to find a structure after python script to be able to feed 4 families with maintaining empty lists how can I do it knowing (that by keeping the structure before flatten I’m a little lost)
If a charitable soul can give me a helping hand I would appreciate it, thank you

import sys
for i in range(1,len(absc)):

OUT = res


May not be the most practical of methods, but is this what you are after?

1 Like

It would help if you explained what it is you’re actually trying to accomplish here. Why do you need empty lists?

It looks like you count the number of occurrences of specific values only to recreate those values in a different order, sort them, and then add them back up and chop them based on the original list lengths. It feels like there’s a better way to handle this.

1 Like

Hi, I am trying to place formwork panels in front of a wall in an automated way (I have 4 panels of different families)

If I send an emptylist in the family instance this eliminates any error messages (and good placement of the mirror elements) on certain walls I have good results especially if the last module is present (in this case there is maintaining the structure sent via ListChop) and no worries about warnings (it is very possible that I will return to the blank copy and rethink everything differently as an approach)

hi and thank you, I’ll try tomorrow and get back to you it’s starting to get late and wake up early tomorrow.

Here are some python list comprehensions which may help

data = [[2.4] * 7, [1.2], [], []]
# [[2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4], [1.2], [], []]

chunks = [len(i) for i in data]
# [7, 1, 0, 0]

flatdata = [i for j in data for i in j]
# [2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 1.2]

result = [round(sum(flatdata[:i]) + flatdata[i] / 2, 1) for i in range(len(flatdata))]
# [1.2, 3.6, 6.0, 8.4, 10.8, 13.2, 15.6, 17.4]

output = [result[sum(chunks[:i]) : sum(chunks[: i + 1])] for i in range(len(chunks))]
# [[1.2, 3.6, 6.0, 8.4, 10.8, 13.2, 15.6], [17.4], [], []]
1 Like

I think I follow. You could always filter out the instances that would be empty since you’re not doing anything with them. The other option is to cleanup what you did by incorporating list length into your current python node so that sublists are created based on the previous list length (0 instances results in an empty list).


Hi, perfect, thanks for sharing knowledge

1 Like