Skip to content

Instantly share code, notes, and snippets.

@BrianHicks
Last active December 14, 2015 15:38
Show Gist options
  • Save BrianHicks/5108847 to your computer and use it in GitHub Desktop.
Save BrianHicks/5108847 to your computer and use it in GitHub Desktop.
sets!
one(1): True
two(2): True
Join/Or!
one_or_two(1): True
one_or_two(2): True
Intersect/And!
one_but_not_two(1): True
one_but_not_two(2): False
def fset(n):
return lambda x: x == n
def set_join(*fsets):
return lambda x: any([f(x) for f in fsets])
def set_intersect(*fsets):
return lambda x: all([f(x) for f in fsets])
one = fset(1)
two = fset(2)
print 'sets!'
assert one(1)
assert two(2)
print 'one(1):', one(1)
print 'two(2):', two(2)
print
print 'Join/Or!'
one_or_two = set_join(one, two)
assert one_or_two(1)
assert one_or_two(2)
print 'one_or_two(1):', one_or_two(1)
print 'one_or_two(2):', one_or_two(2)
print
print 'Intersect/And!'
one_but_not_two = set_intersect(one_or_two, one)
assert one_but_not_two(1)
assert not one_but_not_two(2)
print 'one_but_not_two(1):', one_but_not_two(1)
print 'one_but_not_two(2):', one_but_not_two(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment