Hello Everyone ,
Could someone help me in acheiving required list arrangement
Welcome to the forums!
Can you show us what youâve tried so far? This is probably trickier than it seems, but there are a few ways you could attempt to go about it. Python would certainly be the easiest but you could probably do it with nodes as well.
Welcome to the forums. This is not a âdo my workâ forum, so youâll usually get better responses if you show what youâve attempted so far so that other users can guide you on ways to improve your script.
In this case, I think itâll be of immediate benefit to start thinking of terms and phrases to use in the search tool.
This thread should be what you are looking to do, I came across it by looking up âGroupingâ, âConsecutiveâ, âRepeatedâ, and âSequentialâ until something that matched the problem was found.
Two more approaches for you.
Python approach:
from itertools import groupby
lst = IN[0]
OUT = [[key + '-' + str(len(list(group))) for key,group in groupby(sublst)]for sublst in lst]
DesignScript approach:
sublsts = DSCore .List.Sublists(x<1>,0..1,1);
first_itm = DSCore.List.FirstItem(sublsts<1><1>);
pairs = sublsts == first_itm;
bools = DSCore.List.AllTrue(pairs<1><1>)? false: DSCore.List.AllFalse(
pairs<1><1>)? false:true;
seq = DSCore.List.AllIndicesOf(bools<1>,true)+1;
add_front = 0..0..#DSCore.List.Count(seq);
add_end = DSCore.List.Count(bools<1>);
positions = DSCore.List.AddItemToFront(add_front<1>,
DSCore.List.AddItemToEnd(add_end<1>,seq<1>)<1>);
lengths = DSCore.List.RestOfItems(positions<1>)
-DSCore.List.DropItems(positions<1>,-1);
groups = DSCore.List.Chop(x<1>,lengths<1>);
count = DSCore .List.Count(groups<1><1>);
out = DSCore.List.FirstItem(groups<1><1>) + "-" + count;
Thankyou Everyone .
I will go through all the solutions provide by eachone of you