Extract first item of each sublist in python
I am wondering what is the best way to extract a first item of each sublist in a list of lists and append it to a new list. So if i have:
lst = [[a,b,c], [1,2,3], [x,y,z]]
and i want to pull out a, 1 and x and create a seperate list from those.
lst2.append(x for x in lst)
Using list comprehension:
>>> lst = [['a','b','c'], [1,2,3], ['x','y','z']] >>> lst2 = [item for item in lst] >>> lst2 ['a', 1, 'x']
★ Back to homepage or read more recommendations: