列表有列表解析式,那么字典呢
#!/usr/bin/env python #coding:utf-8 #@Author:Andy """ select data from dict """ from random import randint print('Generate a random dict:') dict1 = {x:randint(30, 80) for x in range(1, 11)} print(dict1) print('Result:') print({k: v for k ,v in dict1.items() if v > 60}) # I can only get the key, Maybe there is some method i don't know keys = list(filter(lambda x: dict1[x] >= 60, dict1 ))