推导式筛选字典数据

# 电脑销售量字典
counts = {'MBP': 268, 'HP': 125, 'DELL': 201, 'Small_mi': 200, 'Lenovo': 199, ' acer': 99}
# 需求:提取上述电脑数量大于等于200的字典数据
count1 = {key: value for key, value in counts.items() if value >= 200}
print(count1)   # {'MBP': 268, 'DELL': 201, 'Small_mi': 200}

  

posted @ 2023-05-18 16:58  sangern  阅读(16)  评论(0)    收藏  举报