Asked By – pleasedontbelong
I’m trying to obtain the n-th elements from a list of tuples.
I have something like:
elements = [(1,1,1),(2,3,7),(3,5,10)]
I wish to extract only the second elements of each tuple into a list:
seconds = [1, 3, 5]
I know that it could be done with a
for loop but I wanted to know if there’s another way since I have thousands of tuples.
Now we will see solution for issue: How to extract the n-th elements from a list of tuples
n = 1 # N. . . [x[n] for x in elements]
This question is answered By – luc
This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0