计算机商店通过使用python字典管理其笔记本电脑库存。每一个字典条目都有一个特定笔记本电脑型号的字符串名作为键,它在库存中的整数量作为对应的值。
例如:
d = {"MS Surface":47, "HP Laptop Probook":144, "MacBook Pro":23, "Dell Laptop XPS": 10, "Asus Chromebook": 20}
定义一个函数low_inventory(laptop_dict,threshold),它返回laptop inventory laptop_dict中数量小于int threshold(<)的所有条目的名称列表。
示例:作为total_items(d,47)调用函数应返回:
['MacBook Pro', 'Dell Laptop XPS', 'Asus Chromebook']
def low_inventory(laptop_dict, threshold):
for akey in laptop_dict.keys():
if laptop_dict[akey] < threshold:
----
你能建议一下怎么做吗?我是python新手,在输出方面很吃力。