Accessing a value in a tuple that is in a list

super9 picture super9 · Jan 26, 2011 · Viewed 127.1k times · Source
[(1,2), (2,3), (4,5), (3,4), (6,7), (6,7), (3,8)]

How do I return the 2nd value from each tuple inside this list?

Desired output:

[2, 3, 5, 4, 7, 7, 8]

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Jan 26, 2011

With a list comprehension.

[x[1] for x in L]