安迪_963

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

列表有列表解析式,那么字典呢

#!/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 ))

 

 

posted on 2017-06-06 17:28  Andy_963  阅读(283)  评论(0编辑  收藏  举报