Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
var x = new Set<T>();
x := make(map[T]bool)
x := make(map[T]struct{})
let x = new Set();
class T(object):
pass
x = set(T())
class T:
...
s = set(T() for _ in range(x))
class Object[T]:
def __init__(self, *args: T):
self.value = args
def __hash__(self):
return hash(self.value)
def __eq__(self, other):
return self.value == other.value
x = set[Object[int]]()
x.add(Object(1))
x.add(Object(2))
x.add(Object(3))
# Or sub-class
class ObjectSet[T](set):
def update(self, *s):
for value in s:
self.add(value)
def add(self, *args: T):
super().add(Object(*args))
x = ObjectSet[int]()
x.update(1, 2, 3)
type Object[T] = T
type ObjectSet[T] = set[Object[T]]
type IntSet = ObjectSet[int]
x: IntSet = set()
x.add(1)
x.add(2)
x.add(3)
val x = Set[T]()