2つ以上のリストのユニオンを見つけるためのC#プログラム
まず、リストを作成します-
//three lists
var list1 = new List{3, 4, 5};
var list2 = new List{1, 2, 3, 4, 5};
var list3 = new List{5, 6, 7, 8}; unionメソッドを使用して、list1とlist2の和集合を取得します-
var res1 = list1.Union(list2); var res2 = res1.Union(list3);
以下は完全なコードです-
例
using System.Collections.Generic;
using System.Linq;
using System;
public class Demo {
public static void Main() {
//three lists
var list1 = new List<int>{3, 4, 5};
var list2 = new List<int>{1, 2, 3, 4, 5};
var list3 = new List<int>{5, 6, 7, 8};
// finding union
var res1 = list1.Union(list2);
var res2 = res1.Union(list3);
foreach(int i in res2) {
Console.WriteLine(i);
}
}
} 出力
3
4
5
1
2
6
7
8
-
2つ以上のリストのユニオンを見つけるPythonプログラム?
和集合演算とは、リスト1とリスト2からすべての要素を取得し、すべての要素を別の3番目のリストに格納する必要があることを意味します。 List1::[1,2,3] List2::[4,5,6] List3::[1,2,3,4,5,6] アルゴリズム Step 1: Input two lists. Step 2: for union operation we just use + operator. サンプルコード # UNION OPERATION A=list() B=list() n=int(input(Enter the size of the List ::)) print(
-
2つのリストで欠落している値と追加の値を見つけるPythonプログラム?
集合論では、集合Aの補集合はAにない要素を指します。集合Bに対するAの相対的な補集合は、集合AとBの差とも呼ばれます。ここではこの原理を適用します。 Pythonには違いの機能があります。 アルゴリズム Step 1 : first we create two user input list. A & B Step 2 : Insert A and B to a set. Step 3 : for finding the missing values of first list we apply difference function, difference of B from