Is there a better way to select percentages?

Hello, I’m somewhat new to coding or at least not very advanced.

I wrote this as a way to select percentages of total objects, in this case panels. The list at the end is used to determine the chop lengths of a list of elements.

It works, but I assume there is a better/ more user friendly way to do this.

thanks.

Percentages of.dyn (33.5 KB)

Hi @j4s0nsm1th1

please check this out: list_percentage.dyn (7.7 KB)

does the same thing:
1

and adding another percentage is easy:

originalListCount = len(IN[0])
percentageList = IN[1:]

output = [round(originalListCount*percentageList[0])]
remainder = round(originalListCount - output[0])

for percent in percentageList[1:]:
	output.append(round(percent*remainder))
	remainder = round(remainder-percent*remainder)
	
output.append(originalListCount - sum(output))

OUT = output

-biboy

3 Likes

that looks great thank you!