Python - Tuples - Retrieve unique elements in list of tuples

ruh

UPDATE:

I went with this:

set(item[1] for item in id) 

Thanks guys, your ideas helped me.


I am working with a list of tuples:

Using the following line of code as an example. My list can be of any lenght. However, I will always be looking for a given index of my tuples:

id = [(9,'Tup','Check'),(10,'Tup','Pyton'),(11,'Not Tup','Stack'),(12,'Not Tup','Stack')]

In this scenario, I am looking to grab the unique second elements.

objective_ouput = ('Tup','Not Tup')
DhiaTN

It as simple as follow:

objective_ouput_set = {item[1] for item in id}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related