Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to sort a list by the second element in tuple python

# lists_of_tuples = [('item', 'price'), ('item', 'price'), ('item', 'price')]
def sort_prices(list_of_tuples): #sort the list b*y the price of each tuple
    list_of_tuples.sort(key=lambda x: x[1], reverse=True) #earse the "reverse" part to sort in small to big.
    return list_of_tuples, print(list_of_tuples)
Comment

PREVIOUS NEXT
Code Example
Python :: pip install speedtest 
Python :: unimport library python 
Python :: how to import image in python 
Python :: jupyter notebook pass python variable to shell 
Python :: pandas remove row if missing value in column 
Python :: f string round 
Python :: python find files recursive 
Python :: python write array to file 
Python :: godot white shader 
Python :: python word cloud 
Python :: matplotlib title 
Python :: install python3 centos 7.8 
Python :: django filter not equal to 
Python :: python open new chrome tab 
Python :: python create map with coordinates 
Python :: python radians to degrees 
Python :: np array value count 
Python :: import matplotlib.pyplot as plt 
Python :: how to refresh windows 10 with python 
Python :: set os environment variable python 
Python :: get active window title python 
Python :: reload all extensions discord.py 
Python :: pandas return first row 
Python :: divide two columns pandas 
Python :: remove single and double quotes from string python 
Python :: jupyter notebook show more rows 
Python :: sort python dictionary by date 
Python :: datetime one month ago python 
Python :: how to switch python version in ubuntu 
Python :: python datetime strptime hour minute second 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =