# Find if an element is unique in the list

**URL:** <https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636>\
**Category:** Lists-Logic\
**Created:** [April 10, 2019, 8:13am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636 "2019-04-10T08:13:46Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![daninet](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@daninet](https://forum.dynamobim.com/u/daninet)\
**Post date:** [April 10, 2019, 8:13am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/1 "2019-04-10T08:13:46Z")

</div>

Hello,  
I have a list [1,1,2,3,4,4,5] and I need [false,false,true,true,false,false,true]

I went in a way where I had like 15 nodes, sorted the indices, counted them, replaced the numbers… it’s a mess. I’m sure there is an obvious easier way just can’t figure it out.

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [April 10, 2019, 8:28am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/2 "2019-04-10T08:28:39Z")

</div>

List.uniqueitems i believe

---

<div class="post-metadata">

**Author:** ![daninet](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@daninet](https://forum.dynamobim.com/u/daninet)\
**Post date:** [April 10, 2019, 9:18am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/3 "2019-04-10T09:18:06Z")

</div>

list unique item gives you the… well… unique items.  
Also the list is shorter. I need a boolean with the same list structure

---

<div class="post-metadata">

**Author:** ![bfreitas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/bfreitas/32/71253_2.png) [@bfreitas](https://forum.dynamobim.com/u/bfreitas)\
**Post date:** [April 10, 2019, 9:28am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/4 "2019-04-10T09:28:47Z")

</div>

Hi @daninet,  
See below python script. It loops the list checking whether the next or previous item are the same. It assumes your input list is ordered.

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

```
list = IN[0]
boolList = []

for i in range(len(list)):
	if i == 0:
		if list[i] == list[i+1]:
			boolList.append(False)
		else:
			boolList.append(True)
	elif i == len(list)-1:
		if list[i] == list[i-1]:
			boolList.append(False)
		else:
			boolList.append(True)
	else:
		if list[i] == list[i-1] or list[i] == list[i+1]:
			boolList.append(False)
		else:
			boolList.append(True)
			
#Assign your output to the OUT variable.
OUT = boolList

```

Cheers

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [April 10, 2019, 9:31am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/5 "2019-04-10T09:31:26Z")

</div>

But combining that and list.contains? 😉

---

<div class="post-metadata">

**Author:** ![daninet](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@daninet](https://forum.dynamobim.com/u/daninet)\
**Post date:** [April 10, 2019, 9:35am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/6 "2019-04-10T09:35:08Z")

</div>

Hello,  
Thank you, this is very close to something I want.  
There are two bugs. Seems like it is not working with this sequence:  
[“Ground Floor”,“Ground Floor Copy 1”,“Ground Floor”,“Ground Floor Copy 1”]  
Else if there is a single element I get a null.

Can you please help with that? 🍺

---

<div class="post-metadata">

**Author:** ![daninet](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@daninet](https://forum.dynamobim.com/u/daninet)\
**Post date:** [April 10, 2019, 9:39am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/7 "2019-04-10T09:39:04Z")

</div>

Yes that was working for me with flat lists but I found it hard to do it with multi level lists.

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [April 10, 2019, 10:04am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/8 "2019-04-10T10:04:18Z")

</div>

Show don’t tell, it is immensely easier if you show what you’re having trouble with

---

<div class="post-metadata">

**Author:** ![daninet](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@daninet](https://forum.dynamobim.com/u/daninet)\
**Post date:** [April 10, 2019, 10:09am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/9 "2019-04-10T10:09:10Z")

</div>

![2019-04-10%2014_05_10-Dynamo](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/9/79840bf03db61fe44236954e047bc9fc31181683.jpeg)

I don’t need the views that are duplicate for my script. I’m using their names (removing a suffix part with string replace) then I need a boolean to filter out the names that are duplicate without the suffix. The views are grouped per sheet so I need to keep the list structure so I can use filterbyboolean

---

<div class="post-metadata">

**Author:** ![daninet](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@daninet](https://forum.dynamobim.com/u/daninet)\
**Post date:** [April 10, 2019, 10:59am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/10 "2019-04-10T10:59:32Z")

</div>

[sample.dyn](https://forum.dynamobim.com/uploads/short-url/67TZICtY8c4jxapkxjdp7J5D3AI.dyn) (13.7 KB)

---

<div class="post-metadata">

**Author:** ![bfreitas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/bfreitas/32/71253_2.png) [@bfreitas](https://forum.dynamobim.com/u/bfreitas)\
**Post date:** [April 10, 2019, 11:27am UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/11 "2019-04-10T11:27:14Z")

</div>

I realize this is not optimal, but if your list will always have those two levels (sheets and views) maybe this can work:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/b/4b336b84f7454141f1d81901c21e458d938617dd.png)  
The python script checks if each item is unique in each of the sublists.

```
def isUnique(item, list):
	count = 0;
	for i in list:
		if item == i:
			count += 1
	return count == 1

#The inputs to this node will be stored as a list in the IN variables.
list = IN[0]
boolList = []

for sublist in list:
	boolSublist = []
	boolList.append(boolSublist)
	for item in sublist:
		boolSublist.append(isUnique(item, sublist))
	
#Assign your output to the OUT variable.
OUT = boolList
```

---

<div class="post-metadata">

**Author:** ![daninet](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@daninet](https://forum.dynamobim.com/u/daninet)\
**Post date:** [April 10, 2019, 12:06pm UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/12 "2019-04-10T12:06:17Z")

</div>

It works. Thank you very much.

I wonder if it is possible to solve with core nodes with bit more flexibility

---

<div class="post-metadata">

**Author:** ![L-Vettz](https://avatars.discourse-cdn.com/v4/letter/l/c5a1d2/32.png) [@L-Vettz](https://forum.dynamobim.com/u/L-Vettz)\
**Post date:** [April 10, 2019, 12:39pm UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/13 "2019-04-10T12:39:19Z")

</div>

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

I had to use one clockwork node (list.countoccurences) but this should do what your asking with nodes only. I think.

---

<div class="post-metadata">

**Author:** ![daninet](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@daninet](https://forum.dynamobim.com/u/daninet)\
**Post date:** [April 10, 2019, 1:02pm UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/14 "2019-04-10T13:02:02Z")

</div>

yes I got very similar with this node, but the structure of the list is not preserved, it’s flat.  
I uploaded a dyn file a little above that shows the intent clearly

---

<div class="post-metadata">

**Author:** ![L-Vettz](https://avatars.discourse-cdn.com/v4/letter/l/c5a1d2/32.png) [@L-Vettz](https://forum.dynamobim.com/u/L-Vettz)\
**Post date:** [April 10, 2019, 1:11pm UTC](https://forum.dynamobim.com/t/find-if-an-element-is-unique-in-the-list/34636/15 "2019-04-10T13:11:02Z")

</div>

I see. Try this instead.

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/c/ac53cb0fd75a7b46cb38fcafa723ed5a50ce3ac6.png)
