Skip to content
Advertisement

Remove elements from tuple array that have same value in first index position of each element

Lets say I have a list:

JavaScript

There are two tuples with ‘a’ as the first element, and two tuples with ‘c’ as the first element. I want to only keep the first instance of each, so I end up with:

JavaScript

How can I achieve that?

Advertisement

Answer

You can use a dictionary to help you filter the duplicate keys:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement