Mega Code Archive

 
Categories / Python Tutorial / Buildin Function
 

Use filter() and lambda to obtain the set of odd numbers from a sequence

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]