filter a user-defined function : filter « Buildin Function « Python Tutorial






from random import randint

def odd(n):
    return n % 2

allNums = []
for eachNum in range(9):
    allNums.append(randint(1, 99))

print filter(odd, allNums)








13.17.filter
13.17.1.Use filter() and lambda to obtain the set of odd numbers from a sequence
13.17.2.filter a user-defined function
13.17.3.filter(function, sequence) returns a sequence items for which function(item) is true
13.17.4.filter a range