[PYTHON] Writing using lambda expressions and filter functions and writing using list comprehensions

(1) How to write using a lambda expression and a filter function

# first 
threes_and_fives = range(1,16)

threes_and_fives = filter(lambda x :x % 3 == 0 or x % 5 == 0, threes_and_fives)

print threes_and_fives

(2) How to write using list comprehension notation

# second: List Comprehension
threes_and_fives = range(1,16)

threes_and_fives = [x for x in range(1,16) if x%3 ==0 or x%5 ==0]

print threes_and_fives

Since you pointed out in the comments, I added / changed the title and text.

Recommended Posts

Writing using lambda expressions and filter functions and writing using list comprehensions
EP 7 Use List Comprehensions Instead of map and filter
Python list comprehensions and generators
Python higher-order functions and comprehensions
Python tuple comprehensions and generator expressions
Apply functions to rows or columns of numpy.array without using list comprehensions
Python comprehension (list and generator expressions) [additional]
About PyQt signal, connect and lambda expressions
List of frequently used built-in functions and methods
filter, map, reduce with js and python (There are also arrow expressions, lambda expressions, comprehension expressions)