Question

def most_expensive_item(price_list: List[list]) -> str: """Return the name of the most expensive item in price_list. Precondition:...

def most_expensive_item(price_list: List[list]) -> str:
"""Return the name of the most expensive item in price_list.

Precondition: price_list is a list of lists in the following format:
[ [str, int], [str, int], ... ]
where each 2-element list represents a name (str) and a
price (int) of an item.
price_list has at least one element.

>>> price_list = [["apple", 1], ["sugar", 5], ["mango", 3],
... ["coffee", 9], ["trail mix", 6]]
>>> most_expensive_item(price_list)

"""

please complete the function body in Python

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def most_expensive_item(price_list):
    item = price_list[0][0]
    cost = price_list[0][1]
    for i in range(1,len(price_list)):
        if(cost<price_list[i][1]):
            cost = price_list[i][1]
            item = price_list[i][0]
    return item

Output:

>> print (most expensive_item ([[apple,1],[sugar,5], [mango,3], [coffee, 9],[trail mix,6]])) coffee

Add a comment
Know the answer?
Add Answer to:
def most_expensive_item(price_list: List[list]) -> str: """Return the name of the most expensive item in price_list. Precondition:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • def calculate_total(price_list: List[list]) -> int: """Return the sum of all second elements in the sublists of...

    def calculate_total(price_list: List[list]) -> int: """Return the sum of all second elements in the sublists of price_list. Precondition: price_list is a list of lists of length 2, and the second element of it sublist is an int. >>> price_list = [["apple", 1], ["sugar", 5], ["mango", 3], ... ["coffee", 9], ["trail mix", 6]] >>> calculate_total(price_list)

  • match_enzymes: (str, List[str], List[str]) -> List[list] The return type is a list of two-item [str, List[int]]...

    match_enzymes: (str, List[str], List[str]) -> List[list] The return type is a list of two-item [str, List[int]] lists The first parameter represents a strand of DNA. The last two parameters are parallel lists: the second parameter is a list of restriction enzyme names, and the third is the corresponding list of recognition sequences. (For example, if the first item in the second parameter is 'BamHI', then the first item in the third parameter would be 'GGATCC', since the restriction enzyme named...

  • def slice_list(lst: List[Any], n: int) -> List[List[Any]]: """ Return a list containing slices of <lst> in...

    def slice_list(lst: List[Any], n: int) -> List[List[Any]]: """ Return a list containing slices of <lst> in order. Each slice is a list of size <n> containing the next <n> elements in <lst>. The last slice may contain fewer than <n> elements in order to make sure that the returned list contains all elements in <lst>. === Precondition === n <= len(lst) >>> slice_list([3, 4, 6, 2, 3], 2) == [[3, 4], [6, 2], [3]] True >>> slice_list(['a', 1, 6.0, False],...

  • COMPLETE THE FOLLOWING QUESTION def find_favourite_artist(filename: str) -> str: ''' Return the name of the artist...

    COMPLETE THE FOLLOWING QUESTION def find_favourite_artist(filename: str) -> str: ''' Return the name of the artist that occurs most frequently in the song file of the given filename. If there are more than one artists that occur most frequently, just return any of them. Note: Feel free to create helper functions for this if you need to. Hint: You may want to use the "sorted" function. ''' pass THE SONG FILE IS: Title, Singer, Release Year Let it go, Idina...

  • Language: Python Topic: API and JSON Function name: min_pop_countries Parameters: region (str), num (int) Return: list...

    Language: Python Topic: API and JSON Function name: min_pop_countries Parameters: region (str), num (int) Return: list of tuples Description: You are working on a project for your Demography class and you are tasked with finding the top num most populous countries in a given region . Instead of looking up on the Internet, you decide to apply your CS1301 knowledge of APIs and write a function to solve the problem for you. Develop a function that takes in a region...

  • List of Indexes Complete the following function. Note that neither item List nor index list should...

    List of Indexes Complete the following function. Note that neither item List nor index list should be mutated 1 from typing import List 3 def find value indexes (iten list: list. index List: Listint). V: object) + List[int]: may appear multiple times in iton list. index list contains zero or more indexes. Return a list of the indexes from index list at which v appears in ite list. Precondition: the values in index_list are valid indexes in its list. >>>...

  • 1)def toggle_cell(row, column, cells): • Return value: Flip the cell in the column of row from...

    1)def toggle_cell(row, column, cells): • Return value: Flip the cell in the column of row from alive to dead or vice versa. Return True if the toggle was successful, False otherwise. • Assumptions: o cells will be a two-dimensional list with at least one row and one element in that row. o row and column are index values of cells • Notes: o Cells is being edited in place. Note that the return value is a Boolean and not a...

  • class Livestock: def __init__(self,name,price_in,utilizations): self.name,self.price_in,self.utilizations = name,float(price_in),utilizations def __lt__(self,other): if self.utilizations is None: return True elif...

    class Livestock: def __init__(self,name,price_in,utilizations): self.name,self.price_in,self.utilizations = name,float(price_in),utilizations def __lt__(self,other): if self.utilizations is None: return True elif other.utilizations is None: return False else: return self.utilizations.count(';') < other.utilizations.count(';') def __eq__(self,other): return self.name == other.name def __repr__(self): return ("{}, {}".format(self.name,self.price_in)) raw_livestock_data = [ # name, price_in, utilizations ['Dog', '200.0', 'Draught,Hunting,Herding,Searching,Guarding.'], ['Goat', '1000.0', 'Dairy,Meat,Wool,Leather.'], ['Python', '10000.3', ''], ['Cattle', '2000.75', 'Meat,Dairy,Leather,Draught.'], ['Donkey', '3400.01', 'Draught,Meat,Dairy.'], ['Pig', '900.5', 'Meat,Leather.'], ['Llama', '5000.66', 'Draught,Meat,Wool.'], ['Deer', '920.32', 'Meat,Leather.'], ['Sheep', '1300.12', 'Wool,Dairy,Leather,Meat.'], ['Rabbit', '100.0', 'Meat,Fur.'], ['Camel', '1800.9', 'Meat,Dairy,Mount.'], ['Reindeer', '4000.55', 'Meat,Leather,Dairy,Draught.'],...

  • def do_action(decision, game_data, current_location, inventory): ''' (int, dict, float, list) -> str Given the game data...

    def do_action(decision, game_data, current_location, inventory): ''' (int, dict, float, list) -> str Given the game data dict, and the current location ID, get all the possible actions at that location. If the decision number given as 'decision' falls outside the number of allowed actions at this location, then return the string "Invalid decision. Please select choice from the decisions listed." Make sure this string is EXACTLY as above. Else, if the decision is valid, then figure out the location information...

  • Fulcrum def can_balance(items): Each item in the list of items is now considered to be a...

    Fulcrum def can_balance(items): Each item in the list of items is now considered to be a physical weight, and therefore guaranteed to be a positive integer. Your task is to find and return a fulcrum position in this list so that when balanced on that position, the total torque of the items to the left of that position equals the total torque of the items to the right of that position. (The item on the fulcrum is assumed to be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT