LoginSignup
2
1

More than 5 years have passed since last update.

【Python】listをbooleanでフィルタリング

Posted at
方法
import itertools

num = [1, 2, 3, 4, 5]
filter = [True, False, False, True, False]

filtered = list(itertools.compress(num, filter))
結果
filtered

[1, 4]
2
1
1

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
1