概要
解決策
上記のパッケージをダウンロードすればPythonのset型を利用できる。
ダウンロード
go get github.com/deckarep/golang-set
使い方
インポート
import ( "github.com/deckarep/golang-set" )
型宣言
str1Set := mapset.NewSet() str2Set := mapset.NewSet()
追加
String型
str1Set.Add("Cooking")
和集合
str1Set.Union(str2Set)
積集合
str1Set.Intersect(str2Set)
差集合
str1Set.Difference(str2Set).Union(str2Set.Difference(str1Set))
特定の文字列が入っているかどうか
str1Set.Contains("Cooking")