Question: I have a list as follows:

```
[(1, 3, 0.0), (1, 4, 0.0), (3, 4, 0.0),(1,3,0.8),(1,2,0.8),(1,1,1)]

```

Is there a way to find the elements that all have 0.0 in index 2 of the tuple in an efficient way? So, I would want to make a list 

```
[(1, 3, 0.0), (1, 4, 0.0), (3, 4, 0.0),(1,3,0.8),(1,2,0.8)]

```

I then want to randomly choose one of the 0.0 and one of the 0.8 to keep.

Basically, I want to find a list of duplicates and keep one element from each duplicate based on index 2 in the tuple. 

I wanted more of an efficient solution since there could be hundreds of thousands of elements in the list and many duplicates. I know how to do this inefficiently with for loops, but struggled to think of a very efficient solution. Thanks!

Answer: 
Run below snippet and Check console html string is there as per you expected.

```js
function playSound(){
   var htmltoappend = "";
    for (i = 1; i < 4; i++) { 
       htmltoappend += '<audio id="sound' + i +'" src="mywebsite/sound'+ i + '.mp3"></audio>'
         htmltoappend += '<img src="mywebsite/image' + i + '.jpg" onclick="document.getElementById("sound'+i+'").play()"/>';
}
  console.log(htmltoappend);
}
playSound();
```
Refactor your line 5 as follows

```
'<img src="mywebsite/image' + i + '.jpg" onclick="document.getElementById("sound' + i + '").play()"/>'

```