hey, as the title said, I want to sort a list of tuples from largest to small:
[("something", "1.1"), ("something else", "5.5")]
but I dont even know how to approach this...
here's the code so far:
def sort_prices(list_of_tuples):
"""The function receives a list of tuples that each have an item and a price.
:param list_of_tuples: a list of tuples.
:type list_of_tuples: list
:return: a list of tuples sorted by the price of the items in them from the largest to the smallest.
:rtype: list
"""
list_of_tuples = list_of_tuples.sort(reverse=True)
return list_of_tuples
def main():
# Call the function sort_prices
products = [('milk', '5.5'), ('candy', '2.5'), ('bread', '9.0')]
sort_prices(products)
print(products)
if __name__ == "__main__":
main()