6 examples of 'python set union' in Python

Every line of 'python set union' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
228def test_union(self):
229 self.assertCodeExecution("""
230 x = frozenset({1, 2, 3})
231 y = frozenset({3, 4, 5})
232 z = [5, 6, 7]
233 w = 1
234 t = frozenset()
235
236 print(x.union(y))
237
238 # empty set test
239 print(x.union(t))
240
241 # multiple args test
242 print(x.union(y, z))
243
244 # iterable test
245 print(x.union(z))
246
247 # not-iterable test
248 try:
249 print(x.union(w))
250 except TypeError as err:
251 print(err)
252 """)
94def union():
95 for x in self:
96 yield x
97 for other in others:
98 for x in other:
99 yield x
41def set_union(arr, *others):
42 pass
72def union(a, b):
73 if isinstance(a, collections.Hashable) and isinstance(b, collections.Hashable):
74 c = set(a) | set(b)
75 else:
76 c = unique(a + b)
77 return c
6def testUnionFind(self):
7 ds = DisjointSet(range(100))
8 for i in range(100):
9 ds.union(i, i % 5)
10 for i in range(100):
11 for j in range(i, 100):
12 self.assertEqual(ds.find_set(i) == ds.find_set(j), i%5 ==j%5)
93def union(*seqs):
94 result = set([])
95 for seq in seqs:
96 if not isinstance(seq, set):
97 seq = set(seq)
98 result |= seq
99 return type(seqs[0])(list(result))

Related snippets