0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Python3: List A から List B の要素を除く

Posted at

リスト内包表記 を使います。

プログラム

remove_list.py
#! /usr/bin/python

list_aa = [1, 2, 3, 3, 4, 5, 4, 5, 6]
list_bb = [4,5]
print(list_aa)
print(list_bb)
bb_set = set(list_bb)
new_list = [item for item in list_aa if item not in bb_set]
print(new_list)

実行結果

$ ./remove_list.py 
[1, 2, 3, 3, 4, 5, 4, 5, 6]
[4, 5]
[1, 2, 3, 3, 6]
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?