Created
April 30, 2017 14:10
-
-
Save tsani/dfd411ac8e330ce1ee668b2b83f92cc7 to your computer and use it in GitHub Desktop.
Partition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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