Skip to content

Instantly share code, notes, and snippets.

@tsani
Created April 30, 2017 14:10
Show Gist options
  • Save tsani/dfd411ac8e330ce1ee668b2b83f92cc7 to your computer and use it in GitHub Desktop.
Save tsani/dfd411ac8e330ce1ee668b2b83f92cc7 to your computer and use it in GitHub Desktop.
Partition
@Function
def partition(f, xs):
""" Partition a sequence according to satisfaction of a predicate.
The result is a tuple in which the first component is a sequence of
unsatisfying elements and the second is a sequence of satisfying elements.
"""
result = ([], [])
for x in xs:
result[1 if f(x) else 0].append(x)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment