LoginSignup
2
2

More than 5 years have passed since last update.

ラムダ式とfilter関数を使った書き方とリスト内包表記を使った書き方

Last updated at Posted at 2014-02-05

(1)ラムダ式とfilter関数を使った書き方

# 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)リスト内包表記を使った書き方

# 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

コメントで指摘していただいたので、タイトル及び本文の追記・変更をしました。

2
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2