In: Computer Science
Python 3.7.4
Costume = {'label': str, 'price': int, 'sizes': [str]}
''' C5. Define a function `most_expensive_costume` that consumes a list of costumes and produces a string representing the label of the costume with the highest price. In the event of a tie, give the label of the item later in the list. If there are no costumes, return the special value None. '''
''' C6. Define a function `find_last_medium` that consumes a list of costumes and produces the label of the last costume that is available in a medium. If no medium costumes are found, produce the special value `None`. '''
''' C7. Define a function `find_first_small` that consumes a list of costumes and produces the label of the first costume that is available in a small. If no small costumes are found, produce the special value `None`. '''
def most_expensive_costume(costumes):
if len(costumes)==0:
return None
highestPrice=costumes[0]['price']
highestPriceLabel=costumes[0]['label']
for i in costumes:
if i['price']>=highestPrice:
highestPrice=i['price']
highestPriceLabel=i['label']
return highestPriceLabel
def find_last_medium(costumes):
for i in costumes[::-1]:
if 'medium' in i['sizes']:
return i['label']
return None
def find_first_small(costumes):
for i in costumes:
if 'small' in i['sizes']:
return i['label']
return None