python show only 1st element of nested lists

Solutions on MaxInterview for python show only 1st element of nested lists by the best coders in the world

showing results for - "python show only 1st element of nested lists"
Matteo
12 Jan 2020
1myList = [[1,2,3],[4,5,6],[7,8,9]]
2
3#Quick answer
4print([ele[0] for ele in myList])   #Prints [1, 4, 7]
5
6#Other variations
7print([[ele[0]] for ele in myList]) #Prints [[1], [4], [7]]
8print([[ele[0] for ele in myList]]) #Prints [[1, 4, 7]]
9
queries leading to this page
how to get the 2 element of the nested list in pythonget first element from list of nested listspython if one list inside another list extract all elemestpython list first items in nested listnested list print first value of listeget the first element from each nested list in a listpython compare sublist last in previous first in nextextract elements for each line in the list pythonpython nested list print first element of eachprint first 5 element of nested list in pythonprint the first element of all list in nested listpython get the first element of all sub lists of a nested listnested list first items as a new listhow to return the first element in a nested listextract only integer from nested list pythoncheck for an element in only first item of a nested list pythonget first element of nested list pythonpython get first element nested listget first item of each list in nested list pythontake first element of nested list pythonget first item of all nested list pythonhow to call first item of nested listnested list print first value of listjs filter first 10 elementsget the first element from each nested list in a list how to print first element of nested list in pythonnested list get first element into a listarray of first elements of nested list pythonextract integer from nested list pythonhow to access all first elements in a nested listhow to return first element in a nested listpython show only 1st element of nested listshow to get a first value of a list inside another listhow to take only first element of nested list in a list 5dtake only the second list of a nested list pythonreturn the first element in a nested listpython show only 1st element of nested lists