Given a list of Tuples, return a new list of the first values of the tuples
I have a list of tuples and I want a new list consisting of the first values of the tuples.
those. if the list is:
[(1.5), (4.10), (100.3), (4.8)]
I want to create the following list:
[1,4,100,4]
The following code works:
a = [(1,5),(4,10),(100,3),(4,8)] l = [] for i in range(len(a)): l.append(a[i][0])
But it seems like there should be a better way, for example:
l = itertools.chain(for i in range(len(a)) a[i][0]) #This won't work
+3
source to share