Question: Python Pls Only One Return statement requires ex_dict = { 'Ceaser': [('Iron', 30, 40), ('Deli' , 20, 50), ('Iron',-10, 60), ('Apron', 20, 55)], 'Baily': [('Iron',
Python Pls
Only One Return statement requires
ex_dict = { 'Ceaser': [('Iron', 30, 40), ('Deli' , 20, 50), ('Iron',-10, 60), ('Apron', 20, 55)], 'Baily': [('Iron', 20, 40), ('Iron',-10, 45), ('Ice', 40, 30), ('Iron',-10, 35)], 'Aaron': [('Iron', 20, 10), ('Dell', 10, 50), ('Apron', 80, 80), ('Deli', -10, 55)], 'Death': [('Apron', 40, 80), ('Apron', 40, 85), ('Apron',-40, 90)] }
def One_return_name:
#Only one return statement (that means you cannot use any other statement.)
#Aaron = 20+10+80+10 = 120
#Death = 40+40+40 = 120
#Baily = 20+10+40+10 = 80
#Ceaser = 30+20+10+20 = 80
#If the result is same, sort by alphabetical order.
Output = ['Aaron', 'Death', 'Baily', 'Ceaser'].
1)Create a function name One_return_name(dicto). This function takes a dictionary and returns the list of the name of people that have largest number of products
For example. only one return line means
def online(db):
return x for x in db.....
so you cannot use any code beside one return statement
2) Create a function one_product_num(dicto). This function take dictionary and returns the list that contains (product name: total_num)
ex_dict = { 'Ceaser': [('Iron', 30, 40), ('Deli' , 20, 50), ('Iron',-10, 60), ('Apron', 20, 55)], 'Baily': [('Iron', 20, 40), ('Iron',-10, 45), ('Ice', 40, 30), ('Iron',-10, 35)], 'Aaron': [('Iron', 20, 10), ('Dell', 10, 50), ('Apron', 80, 80), ('Deli', -10, 55)], 'Death': [('Apron', 40, 80), ('Apron', 40, 85), ('Apron',-40, 90)] }
def one_product_num(dicto)
#Iron = 30+10+20+10+10+20 = 100
#Deli = 20+10+10 = 40
#Ice = 40
#Apron = 20+80+40+40+40 = 220
#If the total number same, sort by alphabetical order
#This one also only can use one return statement
Output = [('Apron ',220), ('Iron',100), ('Deli ',40), ('Ice ',40)]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
