# Adding sequence to create unique values

**URL:** <https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221>\
**Category:** Lists-Logic\
**Tags:** dynamo\
**Created:** [July 10, 2025, 11:45am UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221 "2025-07-10T11:45:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laura\_BIMChick](https://avatars.discourse-cdn.com/v4/letter/l/bbce88/32.png) [@Laura\_BIMChick](https://forum.dynamobim.com/u/Laura_BIMChick)\
**Post date:** [July 10, 2025, 11:45am UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/1 "2025-07-10T11:45:29Z")

</div>

Hi all, my brain is completely fried at the moment, so bear with me.  
I have a list with multiple duplicate values that I want to make unique by adding a 1,2,3,… sequence at the end of the value.

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

A lot of the solutions on here say that the way to go is to group by key but that would mess up my original list order which I want/need to keep.  
I’m open to any other suggestions other than to group by key.  
If it’s not possible I’ll have to rework the majority of my script which I would prefer not to do since my brain is already fried and I’m in a time crunch…

I’ve recreated my values in a seperate script without sharing my full graph:  
[Add sequence.dyn](https://forum.dynamobim.com/uploads/short-url/eaPxg2lQv8ZHllpEZOK0PzEwajy.dyn) (12.6 KB)

My gut says there is probably a solution with python but unfortunately I have not found the time yet to deepdive into python…

---

<div class="post-metadata">

**Author:** ![BimAmbit](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/bimambit/32/192629_2.png) [@BimAmbit](https://forum.dynamobim.com/u/BimAmbit)\
**Post date:** [July 10, 2025, 12:33pm UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/2 "2025-07-10T12:33:44Z")

</div>

one way to accomplish this, line 6 could be slightly confusing we could discuss it further some other time if u r interested:  
[Add sequence.dyn](https://forum.dynamobim.com/uploads/short-url/jQz3oAt2kivlmYfNPKGRSuBrgXN.dyn) (14.4 KB)

```auto
def track_occurences(lst):
    counter = {}
    output = []
    
    for x in lst:
        counter[x] = counter.get(x, 0) + 1
        output.append(x+str(counter[x]))
    
    return output   
OUT = track_occurences(IN[0])

```

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

---

<div class="post-metadata">

**Author:** ![Laura\_BIMChick](https://avatars.discourse-cdn.com/v4/letter/l/bbce88/32.png) [@Laura\_BIMChick](https://forum.dynamobim.com/u/Laura_BIMChick)\
**Post date:** [July 10, 2025, 12:37pm UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/3 "2025-07-10T12:37:44Z")

</div>

Thanks! This is awesome!  
Would this still work if there are no duplicate values? As in, would it add only a ‘1’ if it’s already a unique value?

---

<div class="post-metadata">

**Author:** ![BimAmbit](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/bimambit/32/192629_2.png) [@BimAmbit](https://forum.dynamobim.com/u/BimAmbit)\
**Post date:** [July 10, 2025, 12:39pm UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/4 "2025-07-10T12:39:55Z")

</div>

yeah i think so. credits to line 6.

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [July 10, 2025, 1:36pm UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/5 "2025-07-10T13:36:54Z")

</div>

Hi, I was going in a different direction, but how can we sum terms of terms in sublists?  
You can probably guess that I’m not very good at Python.  
(I almost have to know the number of unique items.)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/f/bf4d7957ac7fdb6034d6a2ad5683ee1e262c9b3e.png)

```auto
import sys
ll=IN[0]

def addcum(l):
    c=0
    rl=[]
    for i in range (1,len(l)+1):
        if l[i-1]==0:
            c=c+0
            rl.append(0)
        else:
            c=c+1
            rl.append(c)
    return rl
cum=[addcum(l) for l in ll]

OUT = [str(i+j+k) for i,j,k in zip(cum[0],cum[1],cum[2])],cum

```

Sincerely,  
christian.stan

edit:

find here  
[https://stackoverflow.com/questions/18713321/element-wise-addition-of-2-lists](https://stackoverflow.com/questions/18713321/element-wise-addition-of-2-lists)

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

---

<div class="post-metadata">

**Author:** ![BimAmbit](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/bimambit/32/192629_2.png) [@BimAmbit](https://forum.dynamobim.com/u/BimAmbit)\
**Post date:** [July 10, 2025, 2:49pm UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/6 "2025-07-10T14:49:45Z")

</div>

unpacking operator should be helpful. but im fascinated by the fact u made a binary mask. im thinkin numpy/pandas could have some one liners to solve op’s problem.

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [July 10, 2025, 3:04pm UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/7 "2025-07-10T15:04:20Z")

</div>

Not yet at the level sufficient to understand all the words but I hope one day, thanks again 😉  
cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![BimAmbit](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/bimambit/32/192629_2.png) [@BimAmbit](https://forum.dynamobim.com/u/BimAmbit)\
**Post date:** [July 10, 2025, 3:10pm UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/8 "2025-07-10T15:10:27Z")

</div>

and thank u! first looked at op’s question, i didn’t think of approaching it the way u did. nice work as always!

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [July 10, 2025, 5:31pm UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/9 "2025-07-10T17:31:50Z")

</div>

> [@Laura\_BIMChick](#):
>
> but that would mess up my original list order

Not necessarily. You also group the indices simultaneously to track their positions.

```auto
lst1 = List.GroupByKey(lst0,lst0)["groups"];
lst2 = List.GroupByKey(1..List.Count(lst0),lst0)["groups"];
lst3 = lst1 + (1..List.Count(lst1<1>));
List.SortByKey(List.Flatten(lst3,-1),List.Flatten(lst2,-1))["sortedList"];

```

 ![sfx2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/0/7044ce2158618dd249ba7ea4e814307d2235aab0.png)

 ![sfx1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/2/125594568188aa4b0c4e25f2647ee476e6ec8c8e.png)

[sfx.dyn](https://forum.dynamobim.com/uploads/short-url/h82SxI6obPHFXWlFFhp17SdWVrX.dyn) (23.3 KB)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [July 10, 2025, 5:57pm UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/10 "2025-07-10T17:57:53Z")

</div>

I mean… if @Vikram_Subbaiah is going to go design script with it…

Here’s a sample design script definition which just iterates over the list, appending an incrementing number to each item in the list until it gets a unique value for all items. All items are sequential so order isn’t of consequence. Execution time seems fairly good in my testing, but admittedly I didn’t try 10000000 item deep lists.

```auto
def uniquifyStrings (lst: string[])
{
	newList = [Imperative]
	{
		myList = [];
		for (i in lst)
		{
			noFit = true;
			numb = 1;
			orig = i;
			while (noFit)
			{
				if (List.Contains(myList,i))
				{
					i = orig+numb;
					numb = numb+1;
				}
				else
				{
					myList = List.Join([myList,i]);
					noFit = false;
				}
			}
		}
		return myList;
	};
	return newList;
};

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/2/e2b938170c8a80c52214ed1f5d9109e0c7697d51.jpeg)

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [July 11, 2025, 12:45am UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/11 "2025-07-11T00:45:07Z")

</div>

> [@BimAmbit](#):
>
> could have some one liners to solve op’s problem

```python
OUT = [v + str(IN[0][:i].count(v)) for i, v in enumerate(IN[0], 1)]

```

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

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [July 11, 2025, 1:02am UTC](https://forum.dynamobim.com/t/adding-sequence-to-create-unique-values/111221/12 "2025-07-11T01:02:32Z")

</div>

Same idea with OOTB Nodes

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/d/ad48afcdc67c5bba19230a46f0f6a0f7b34332cf.png)
