Open jab opened 6 years ago
Know thine equalities
>>> d = {1: int, 1.0: float, True: bool} >>> d[1.0] <class 'bool'> >>> 1+0j in d True
especially when intransitive
>>> from collections import OrderedDict >>> d = dict([(0, 1), (2, 3)]) >>> od = OrderedDict([(0, 1), (2, 3)]) >>> od2 = OrderedDict([(2, 3), (0, 1)]) >>> d == od True >>> d == od2 True >>> od == od2 False >>> class MyDict(dict): ... __hash__ = lambda self: 0 ... >>> class MyOrderedDict(OrderedDict): ... __hash__ = lambda self: 0 ... >>> d = MyDict([(0, 1), (2, 3)]) >>> od = MyOrderedDict([(0, 1), (2, 3)]) >>> od2 = MyOrderedDict([(2, 3), (0, 1)]) >>> len({d, od, od2}) 1 >>> len({od, od2, d}) 2
❤️ ❤️ ❤️
Know thine equalities
especially when intransitive
❤️ ❤️ ❤️