4 examples of 'python set contains' in Python

Every line of 'python set contains' 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
this disclaimer
101def __contains__(self, value):
102 return value in self._dict
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

274def __contains__(self, x):
275 """
276 Return True if $x$ is in self.
277
278 EXAMPLES::
279
280 sage: X = Set(ZZ)
281 sage: 5 in X
282 True
283 sage: GF(7)(3) in X
284 True
285 sage: 2/1 in X
286 True
287 sage: 2/1 in ZZ
288 True
289 sage: 2/3 in X
290 False
291
292 Finite fields better illustrate the difference between
293 __contains__ for objects and their underlying sets.
294
295 sage: X = Set(GF(7))
296 sage: X
297 {0, 1, 2, 3, 4, 5, 6}
298 sage: 5/3 in X
299 False
300 sage: 5/3 in GF(7)
301 False
302 sage: Set(GF(7)).union(Set(GF(5)))
303 {0, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 0}
304 sage: Set(GF(7)).intersection(Set(GF(5)))
305 {}
306 """
307 return x in self.__object
124def __contains__(self, element):
125 try:
126 return element in self._data
127 except TypeError:
128 transform = getattr(element, '__as_temporarily_immutable__', None)
129 if transform is None:
130 raise
131 return transform() in self._data
132
133 return
22def issubset(self, items):
23 JS("""
24 for (var i in self.d) {
25 if (!items.__contains__(i)) return false;
26 }
27 return true;
28 """)

Related snippets