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...

  • How do you do this? class Event: """A new calendar event.""" def __init__(self, start_time: int, end_time:...

    How do you do this? class Event: """A new calendar event.""" def __init__(self, start_time: int, end_time: int, event_name: str) -> None: """Initialize a new event that starts at start_time, ends at end_time, and is named name. Precondition: 0 <= start_time < end_time <= 23 >>> e = Event(12, 13, 'Lunch') >>> e.start_time 12 >>> e.end_time 13 >>> e.name 'Lunch' """    self.start_time = start_time self.end_time = end_time self.name = event_name def __str__(self) -> str: """Return a string representation of this...

  • PYTHON FILL IN THE BLANK CODE REMEMBER TO UTILIZE DICTIONARIES # Implement this function: def store_checkout(inventory_tuple_list,...

    PYTHON FILL IN THE BLANK CODE REMEMBER TO UTILIZE DICTIONARIES # Implement this function: def store_checkout(inventory_tuple_list, item_purchase_list): """ inventory_tuple_list: A list of tuples. Each tuple has a string representing an item name, an int representing a price, and a string representing a description. Example: [("A", 5, "shiny new A"), ("B", 10, "big heavy B")] item_purchase_list: A list of strings. Each string represents an item name. Example: ["A", "A", "B", "C"] Return the total price of the items in item_purchase_list by...

  • 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. >>>...

  • Language: Python Topic: APIs and JSON Function name: can_visit Parameters: country_code (str), langList (list of strings...

    Language: Python Topic: APIs and JSON Function name: can_visit Parameters: country_code (str), langList (list of strings ) Return: boolean Description: You are looking for a country to visit for SB2K19 and want to ensure that you know how to speak at least one of the languages spoken in that country. Given a country_code (str), a three - letter code representing the country you want to visit, and a langList (list), a list of the names of the languages you know...

  • 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...

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