Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sort tuple by first element python

a = [(5,8), (3,4), (9,7)]

#sort by first element in tuple
result = sorted(a, key=lambda tup: tup[0])

#OR to do inplace sort:

a.sorted(key = lambda tup: tup[0])

# output
[(3, 4), (5, 8), (9, 7)]
Comment

Sort python list by first element

li = [[1,4,7],[3,6,9],[2,59,8]]
li.sort(key=lambda x: int(x[0]))
Comment

Sort python list by first element

>>> lis = [[1,4,7],[3,6,9],[2,59,8]]
>>> lis.sort()
>>> lis
[[1, 4, 7], [2, 59, 8], [3, 6, 9]]
Comment

PREVIOUS NEXT
Code Example
Python :: python saving a screentshot with PIL 
Python :: python get stack trace 
Python :: python urlencode 
Python :: how to make a hidden file in python 
Python :: deleting all rows in pandas 
Python :: running selenium on google colab 
Python :: split data into training, testing and validation set python 
Python :: EnvironmentError command line 
Python :: request url in web scraping 
Python :: get common elements from two lists 
Python :: pyaudio not installing ubuntu 
Python :: python get output of command to variable 
Python :: convert numpy to torch 
Python :: how to delete row pandas in for loop 
Python :: python check file extension 
Python :: save plot python 
Python :: get the torch version 
Python :: export dataframe to csv python 
Python :: selenium driver wait python 
Python :: python find smallest element in dictionary 
Python :: python cv2 read image grayscale 
Python :: dataframe all companies except 
Python :: read google sheet from web to pandas python 
Python :: DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning. 
Python :: how to set the screen brightness using python 
Python :: how do i print the entire array pthon jupyter 
Python :: python get time of day 
Python :: dataframe column contains string 
Python :: python dictionary sort in descending order 
Python :: how to install pandas datareader in conda 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =