(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