# Get Indices of repetitive elements from a list

**URL:** <https://forum.dynamobim.com/t/get-indices-of-repetitive-elements-from-a-list/32469>\
**Category:** Developers\
**Tags:** python, dynamo\
**Created:** [February 21, 2019, 2:37pm UTC](https://forum.dynamobim.com/t/get-indices-of-repetitive-elements-from-a-list/32469 "2019-02-21T14:37:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vamsi736](https://avatars.discourse-cdn.com/v4/letter/v/4af34b/32.png) [@vamsi736](https://forum.dynamobim.com/u/vamsi736)\
**Post date:** [February 21, 2019, 2:37pm UTC](https://forum.dynamobim.com/t/get-indices-of-repetitive-elements-from-a-list/32469/1 "2019-02-21T14:37:02Z")

</div>

I have 2 lists “list 1” “list 2” I want to get indices of “0” from “list 2” and by using those values I want to get the values from list1

Input  
list1 = [50,45,40,35,30,25,20,15,10,5]  
list2 = [0,0,5,1,1,0,3,0,1,1]

Expecting Output  
output = [50,45,25,15]

But the problem is I can get the indices of all “0” from list2

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

I would like to know how to get the indices for duplicate elements

Thank you

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [February 21, 2019, 4:43pm UTC](https://forum.dynamobim.com/t/get-indices-of-repetitive-elements-from-a-list/32469/2 "2019-02-21T16:43:06Z")

</div>

The index method will only return the first found index. So, when you append list2.index(0) to your indexnumber list, it will always append 0, since that is the first index of that value in list2. However, you don’t necessarily need to know the index at all. Here is an alternative method to achieve the same thing:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/c/8c28a46c13359821fc2feebfd3b88280c14a7e97.png)  
[Indexes.dyn](https://forum.dynamobim.com/uploads/short-url/f1iSvjANGyblHdBKtxumcWhlAkP.dyn) (7.4 KB)

Essentially, this takes each list an associates their respective values at the same index through a `zip()` function. Where the second value is equal to 0, it will append the first value to a new list `subset`.

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [February 22, 2019, 1:33am UTC](https://forum.dynamobim.com/t/get-indices-of-repetitive-elements-from-a-list/32469/3 "2019-02-22T01:33:45Z")

</div>

This can be done in nodes/codeblock form pretty easily too.

 ![repetitiveelementsinlist](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/a/fadbf3d4772f512b65c1fa9363febcbe177696e2.png)

> [@vamsi736](#):
>
> I would like to know how to get the indices for duplicate elements

GroupByKey would work for this as well, see the blue group in the above image.
