Question

In: Computer Science

Python 3.7.4 Costume = {'label': str, 'price': int, 'sizes': [str]} ''' C5. Define a function `most_expensive_costume`...

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

Solutions

Expert Solution

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


Related Solutions

Write a function called is_valid_phone_number matches that takes two int arrays and their respective sizes, and...
Write a function called is_valid_phone_number matches that takes two int arrays and their respective sizes, and returns the number of consecutive values that match between the two arrays starting at index 0. Suppose the two arrays are {3, 2, 5, 6, 1, 3} and {3, 2, 5, 2, 6, 1, 3} then the function should return 3 since the consecutive matches are for values 3, 2, and 5. in C++ with explanations
(Python) Define a function makeTwoWay that expects a singly linked structure as its argument. The function...
(Python) Define a function makeTwoWay that expects a singly linked structure as its argument. The function builds and returns a doubly linked structure that contains the items in the singly linked structure. (Note: The function should not alter the argument's structure.) node.py source code: """ File: node.py Node classes for one-way linked structures and two-way linked structures. """ class Node(object):     def __init__(self, data, next = None):         """Instantiates a Node with default next of None"""         self.data = data...
Write a complete C program to do the following:(i) Define a function Nodeptr CreateDLL(char str[])which takes...
Write a complete C program to do the following:(i) Define a function Nodeptr CreateDLL(char str[])which takes a string as parameter and creates a Doubly Linked List of characters and returns the pointer to the first node. (ii) Define a function int IsPalindrome(Nodeptr first)to check whether the string represented by the above doubly linked list pointed to by first, is a palindrome or not and return 1/0 accordingly. Do not use any additional data structure.Write a main function to read a...
python 3 please Define a function voweliest that takes as input a string and returns as...
python 3 please Define a function voweliest that takes as input a string and returns as output a tuple where the string that has the most vowels in it is the first element and the second is the number of vowels in that string. Note: don't worry about ties or capital letters Hint: consider defining and using a separate function that counts the number of vowels in a given string
Python question Write a function int(lofi, alofi) that consumes two sorted lists of distinct integers lofi...
Python question Write a function int(lofi, alofi) that consumes two sorted lists of distinct integers lofi and alofi, and returns a sorted list that contains only elements common to both lists. You must obey the following restrictions: No recursion or abstract list functions, intersect must run in O(n) where n is the combined length of the two parameters. sort function is not allowed as well as list comprehensions math is the only library that can be imported Example: int([4, 13,...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
Write python 3 code to define a function that uses three arguments, and returns a result....
Write python 3 code to define a function that uses three arguments, and returns a result. The function returns True if the first argument is more than or equal to the second argument and less than or equal to the third argument, otherwise it returns False. Write a python 3 code for function main, that does the following: creates a variable and assign it the value True. uses a while loop which runs as long as the variable of the...
a. Define the demand function of a good, and then discuss the price elasticity of demand...
a. Define the demand function of a good, and then discuss the price elasticity of demand for agricultural product such as rice. b. Use a demand/supply diagram to discuss why rice farmers may not benefit from a technological improvement in producing rice.
a. Define the demand function of a good, and then discuss the price elasticity of demand...
a. Define the demand function of a good, and then discuss the price elasticity of demand for agricultural product such as rice. b. Use a demand/supply diagram to discuss why rice farmers may not benefit from a technological improvement in producing rice.
Python 3 Forming Functions Define and complete the functions described below. * function name: say_hi *...
Python 3 Forming Functions Define and complete the functions described below. * function name: say_hi * parameters: none * returns: N/A * operation: just say "hi" when called. * expected output: >>> say_hi() hi * function name: personal_hi * parameters: name (string) * returns: N/A * operation: Similar to say_hi, but you should include the name argument in the greeting. * expected output: >>> personal_hi("Samantha") Hi, Samantha * function name: introduce * parameters: name1 (string) name2 (string) * returns: N/A...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT