Skip to content

Instantly share code, notes, and snippets.

View pzelnip's full-sized avatar
🤷‍♂️

Adam Parkin pzelnip

🤷‍♂️
View GitHub Profile
@pzelnip
pzelnip / gist:2696496
Created May 14, 2012 20:23
Define all rich comparison operators in terms of lt
class ComparableMixin:
def __eq__(self, other):
return not (self < other or other < self)
def __le__(self, other):
return not other < self
class Foo(ComparableMixin):
def __init__(self, val):
self.val = val
import random
import timeit
from copy import deepcopy
def inter_reduce(sets):
return reduce(set.intersection, sets)
def inter_for_deepcopy(sets):
sets = iter(sets)
result = deepcopy(next(sets))