Answer:
Here is the completed code for this problem. Comments are included, go through it, learn how things work.
Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.
Step-by-step explanation:
#code
#required method taking a db as parameter
def by_product_inventory_count(db):
#one line statement, which initially creates a list of all keys (warehouse names)
#from the dict using a list comprehension, then sorts it by length of the inner dict
#represented by each warehouse name, and if the length is same, sorts by key itself
#(alphabetically), and returns this sorted list
return sorted([key for key in db],key=lambda x:(len(db[x]),x))
#creating a db and testing the method
db={'Irvine' : {'brush': 3, 'comb': 2, 'wallet': 2}, 'Newport': {'comb': 7, 'stapler': 0},
'Tustin' : {'keychain': 3, 'pencil': 4, 'wallet': 3}}
sorted_warehouse_names=by_product_inventory_count(db)
print(sorted_warehouse_names)
#OUTPUT
['Newport', 'Irvine', 'Tustin']