你可以试试滤镜
value = filter(lambda x: dict[x] < 3, keys)
以及其他迭代函数
http://book.pythontips.com/en/latest/map_filter.html