Use filter() and lambda to obtain the set of odd numbers from a sequence : filter « Buildin Function « Python Tutorial






seq = [23, 9, 7, 18, 12, 11, 12, 11, 10, 9, 9, 10, 10, 9, 8 ]
print filter(lambda x: x % 2, seq)
print [x for x in seq if x % 2]








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