# Sum concecutive strings

**URL:** <https://forum.dynamobim.com/t/sum-concecutive-strings/73418>\
**Category:** Lists-Logic\
**Created:** [February 16, 2022, 9:00pm UTC](https://forum.dynamobim.com/t/sum-concecutive-strings/73418 "2022-02-16T21:00:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![skot](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@skot](https://forum.dynamobim.com/u/skot)\
**Post date:** [February 16, 2022, 9:00pm UTC](https://forum.dynamobim.com/t/sum-concecutive-strings/73418/1 "2022-02-16T21:00:30Z")

</div>

Hello Everyone ,

Could someone help me in acheiving required list arrangement

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/2/5249670371bc5ca0d5ff0b993bf83e4fbb160412.png)

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [February 16, 2022, 9:15pm UTC](https://forum.dynamobim.com/t/sum-concecutive-strings/73418/2 "2022-02-16T21:15:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hamish](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Hamish](https://forum.dynamobim.com/u/Hamish)\
**Post date:** [February 16, 2022, 9:22pm UTC](https://forum.dynamobim.com/t/sum-concecutive-strings/73418/3 "2022-02-16T21:22:29Z")

</div>

Edit: Removed, misinterpreted your request given the simplified example.

Edit 2: Actually, that solution does what I think you’re after with a couple changes:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/9/c9fa072d21ef0895a134d2deee45128c44f9685d.png)

That custom node is just this Python:

```auto
from itertools import groupby

group = groupby(IN[0])

OUT = [list(i) for j,i in group]

```

---

<div class="post-metadata">

**Author:** ![Robert\_Younger](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/robert_younger/32/205603_2.png) [@Robert\_Younger](https://forum.dynamobim.com/u/Robert_Younger)\
**Post date:** [February 16, 2022, 9:30pm UTC](https://forum.dynamobim.com/t/sum-concecutive-strings/73418/4 "2022-02-16T21:30:26Z")

</div>

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.

> [@Group Repeated Sequential Items in List](https://forum.dynamobim.com/t/group-repeated-sequential-items-in-list/62329/5):
>
> Python can help you directly get that as well! from itertools import groupby OUT = [keyValue for keyValue,groups in groupby(IN[0])] Or you can do something using the OOTB nodes like this. I took this [post](https://forum.dynamobim.com/t/split-the-list-by-boolean/62093/13) as a base but I’m sure there would be better node solutions out there. [SplitList.dyn](https://forum.dynamobim.com/uploads/short-url/jfcxkk2FIp50l7yZE6RqeR2HJRC.dyn) (32.5 KB)

 ![List Local Grouping_2022-02-16_01-31-53](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/1/c18136c202124fb2ded78ad6b563f1a26c63629b.png)  
Same script as the link, but with nodes grouped and explained

---

<div class="post-metadata">

**Author:** ![EdsonMatt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/edsonmatt/32/124725_2.png) [@EdsonMatt](https://forum.dynamobim.com/u/EdsonMatt)\
**Post date:** [February 16, 2022, 10:15pm UTC](https://forum.dynamobim.com/t/sum-concecutive-strings/73418/5 "2022-02-16T22:15:20Z")

</div>

Two more approaches for you.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/5/7565c6896cb4f1d788e29d79ca05288b9d226a0f.png)

Python approach:

```auto
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:

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [February 17, 2022, 11:28am UTC](https://forum.dynamobim.com/t/sum-concecutive-strings/73418/6 "2022-02-17T11:28:53Z")

</div>

Another solution

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/0/70d79d1cb457298635ad77c4abd30e703cfe5b69.png)

```auto
import sys

lstInput = IN[0]

OUT = [sorted(["{}-{}".format(txt, sublst.count(txt)) for txt in set(sublst)]) for sublst in lstInput]

```

---

<div class="post-metadata">

**Author:** ![skot](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@skot](https://forum.dynamobim.com/u/skot)\
**Post date:** [February 17, 2022, 6:43pm UTC](https://forum.dynamobim.com/t/sum-concecutive-strings/73418/7 "2022-02-17T18:43:21Z")

</div>

Thankyou Everyone .  
I will go through all the solutions provide by eachone of you
