Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python show only 1st element of nested lists

myList = [[1,2,3],[4,5,6],[7,8,9]]

#Quick answer
print([ele[0] for ele in myList])   #Prints [1, 4, 7]

#Other variations
print([[ele[0]] for ele in myList]) #Prints [[1], [4], [7]]
print([[ele[0] for ele in myList]]) #Prints [[1, 4, 7]]
Comment

PREVIOUS NEXT
Code Example
Python :: win32api.mouse_event python 
Python :: print type(x) in python 
Python :: pyqt5 qpushbutton disable 
Python :: get first element of ordereddict 
Python :: get ip address in django 
Python :: highlight max value in table pandas dataframe 
Python :: python write txt utf8 
Python :: how to address a column in a 2d array python 
Python :: url in form action django 
Python :: set password on a zip file in python 
Python :: making variable if it is none python 
Python :: pandas transform date format? 
Python :: how to fill missing values dataframe with mean 
Python :: pandas replace values with only whitespace to null 
Python :: how to sort dictionary in python by value 
Python :: real time crypto prices python 
Python :: count gabarit django 
Python :: django modelform style 
Python :: NumPy flip Example 
Python :: python print char n times 
Python :: flask_mail 
Python :: python selenium implicit wait 
Python :: django rest framework default_authentication_classes 
Python :: Python - Count the Number of Keys in a Python Dictionary 
Python :: icon tkiner 
Python :: how to make sun as first day in calendar python 
Python :: beautifulsoup find_all by id 
Python :: python if variable is greater than 
Python :: minimum-number-of-steps-to-reduce-number-to-1 
Python :: python if string is null or whitespace 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =