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
public int static mirroringIt(String str){ return n; } implement this function so its takes ONE string...
public int static mirroringIt(String str){ return n; } implement this function so its takes ONE string and remove the characters so it becomes a mirrored word. example: Input: qswwbi Output: 4 remove q s b i "wow" is a mirror word. output : 0 Input : "if" output : 1 remove either I or f because it's two words. don't use 3rd parties library or java.util.
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) 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 Python module that must satisfy the following- Define a function named rinsert. This function...
Write a Python module that must satisfy the following- Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less than the second parameter’s index.   Define a function named rinsort. This...
Define a Python function which finds the all of the odd numbers and the product of...
Define a Python function which finds the all of the odd numbers and the product of the odd numbers. (Use for loop and if conditions for this problem. Do not use existing codes. Use your own codes).(You need to use append function to obtain a list of odd numbers)
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
Using Python 3, define mySum function that supposed to return the sum of a list of...
Using Python 3, define mySum function that supposed to return the sum of a list of numbers (and 0 if that list is empty), but it has one or more errors in it. Write test cases to determine what errors there are.
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,...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT