lamba

>>> from random import randint
>>> allNums = []
>>> for eachNum in range(10):
allNums.append(randint(1000,9999))

>>> print '随机从1000-9999生成的数字中获取的10个值为:'+ str(allNums)
随机从1000-9999生成的数字中获取的10个值为:[8160, 3230, 9253, 9503, 4131, 9442, 6558, 5657, 1062, 5394]
>>> print '偶数的有:'+str(filter(lambda n:n%2==0, allNums))
偶数的有:[8160, 3230, 9442, 6558, 1062, 5394]
>>> print '奇数的有:'+str(filter(lambda n:n%2!=0, allNums))
奇数的有:[9253, 9503, 4131, 5657]
>>>

原文地址:https://www.cnblogs.com/L-H-R-X-hehe/p/3826482.html