Skip to content

Instantly share code, notes, and snippets.

@roman-on
Created May 17, 2020 23:05
Show Gist options
  • Save roman-on/f74bb7b08bb5c5bd7cd133eb2d8c3a98 to your computer and use it in GitHub Desktop.
Save roman-on/f74bb7b08bb5c5bd7cd133eb2d8c3a98 to your computer and use it in GitHub Desktop.
"""
The function receives a list of tables in each item and its price.
The function returns a list of sorted tables based on the price of the items that are large to small.
Define the list of tables that the function gets the following:
[('Item', 'price'), ('item', 'price'), ('item', 'price')]
Notice that all organs are of the price string type written as a whole clown number.
Run_ information of the sort_prices function
>>> products = [('Milk', '5.5'), ('Candy', '2.5'), ('Bread', '9.0')]
>>> sort_prices (products)
OUTPUT
[('Bread', '9.0'), ('Milk', '5.5'), ('Candy', '2.5')]
"""
products = [('milk', '5.5'), ('candy', '2.5'), ('bread', '9.0')]
def MyFn(s):
return s[-1]
def sort_prices(list_of_tuples):
return sorted(products, key=MyFn, reverse=True)
INPUT:
sort_prices(products)
OUTPUT:
[('bread', '9.0'), ('milk', '5.5'), ('candy', '2.5')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment