0
0

More than 1 year has passed since last update.

配列 と 集合

Posted at

目的

  • 配列同士の演算の仕方を理解する

ポイント

  • 和集合は、配列に含まれる全ての値をとる
  • 積集合は、どちらの配列にもある値をとる
  • 差集合は、配列から重複する部分以外の値をとる

書き方の例

numbers_a = [1, 2, 3]
numbers_b = [3, 4, 5]

p numbers_a | numbers_b  #和集合
p numbers_a & numbers_b  #積集合

p numbers_a - numbers_b  #差集合
p numbers_b - numbers_a

~実際の表示~
[1, 2, 3, 4, 5]
[3]
[1, 2]
[4, 5]

注意するポイント

  • 差集合は、左辺で重複していて右辺にはない要素は除かれない
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