Last login: Mon Feb 14 11:30:20 on ttys001 The default interactive shell is now zsh. To update your account to use zsh, please run `chsh -s /bin/zsh`. For more details, please visit https://support.apple.com/kb/HT208050. MAC:Mon Feb 14:13:57:~> python Python 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> hash("234234") 1253237667222338117 >>> hash("234235") 573218971702271740 >>> hash(0) 0 >>> hash(1) 1 >>> hash(2**20) 1048576 >>> #when does an integer hash to itself >>> hash((2,2,2)) -2342735517975372153 >>> hash([1,2,3]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list' >>> ## mutable objects are uhashable >>> >>> s = set() >>> type(s) <class 'set'> >>> len(s) 0 >>> s.add("a") >>> s {'a'} >>> s.add("b") >>> s {'b', 'a'} >>> s.add("cackleberry") >>> s {'cackleberry', 'b', 'a'} >>> s.add(4.5) >>> s {'cackleberry', 'b', 4.5, 'a'} >>> s.add("b") >>> s {'cackleberry', 'b', 4.5, 'a'} >>> ## equality is decided by == >>> s {'cackleberry', 'b', 4.5, 'a'} >>> "quack" in s False >>> "b" in S Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'S' is not defined. Did you mean: 's'? >>> "b" in s True >>> 1 in [1,2,3,4] True >>> "oa" in "toad" True >>> s = {"a", "b", "c", "x", "y", ... ... "z} File "<stdin>", line 3 "z} ^ SyntaxError: unterminated string literal (detected at line 3) >>> s = {"a", "b", "c", "x", "y", "z"} >>> s {'b', 'c', 'a', 'z', 'x', 'y'} >>> t = {"c", "d", e", "w", "x", "y"} File "<stdin>", line 1 t = {"c", "d", e", "w", "x", "y"} ^^^^^ SyntaxError: invalid syntax. Perhaps you forgot a comma? >>> t = {"c", "d", e", "w", "x", "y"} File "<stdin>", line 1 t = {"c", "d", e", "w", "x", "y"} ^^^^^ SyntaxError: invalid syntax. Perhaps you forgot a comma? >>> t = {"c", "d", "e", "w", "x", "y"} >>> s {'b', 'c', 'a', 'z', 'x', 'y'} >>> t {'w', 'c', 'e', 'd', 'x', 'y'} >>> s | t {'b', 'd', 'x', 'w', 'c', 'a', 'z', 'e', 'y'} >>> s.union(t) {'b', 'd', 'x', 'w', 'c', 'a', 'z', 'e', 'y'} >>> s.intersect(t) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'set' object has no attribute 'intersect'. Did you mean: 'intersection'? >>> s.intersection(t) {'x', 'y', 'c'} >>> s & t {'x', 'y', 'c'} >>> s - t {'b', 'z', 'a'} >>> t - s {'d', 'w', 'e'} >>> s.difference(t) {'b', 'z', 'a'} >>> ## puzzler: if B - A = C - A is B = C? >>> len(s) 6 >>> s {'b', 'c', 'a', 'z', 'x', 'y'} >>> t {'w', 'c', 'e', 'd', 'x', 'y'} >>> s ^ t {'b', 'w', 'z', 'e', 'a', 'd'} >>> s.isdisjoint(t) False >>> s & t {'x', 'y', 'c'} >>> s.discard("x") >>> s {'b', 'c', 'a', 'z', 'y'} >>> t.discard("y") >>> s & t {'c'} >>> t.discard("c") >>> s {'b', 'c', 'a', 'z', 'y'} >>> t {'w', 'e', 'd', 'x'} >>> s.isdisjoint(t) True >>> a = {1,2,3} >>> b = {3,4,5} >>> c = {1,2,3,4,5} >>> a < b False >>> b < a False >>> b == a False >>> a < c True >>> a < a False >>> a <= a True >>> c <= c True >>> a <= c True >>> a.subset(b) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'set' object has no attribute 'subset'. Did you mean: 'issubset'? >>> a.issubset(b) False >>>