📌  相关文章
📜  如何按元组python代码示例中的第二个元素对列表进行排序

📅  最后修改于: 2022-03-11 14:46:02.524000             🧑  作者: Mango

代码示例1
# 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)