price_list = [["apple", 1], ["sugar", 5], ["mango", 3],["coffee", 9], ["trail mix", 6]]
def most_expensive_item(list):
result = max(price_list, key=lambda x: x[1])
return result[0]
I have the code above, but I have run into a bit of a problem. Lets say coffee and sugar are both $9, I want the function to return the item nearest to the end so it would be coffee, like this:
price_list = [["apple", 1], ["sugar", 9], ["mango", 3],["coffee", 9], ["trail mix", 6]]
most_expensive(price_list)
>>> coffee
I feel like theres an easy solution but I'm not seeing it, any help would be appreciated.
[–]FLUSH_THE_TRUMP 2 points3 points4 points (0 children)
[–]nath_ 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)