Commit 2de64672 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a partition function to split a list in two



This is similar to the Haskell function, except that the signature is
reverse to match the 'any' and 'all' Python functions.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 1b334175
......@@ -1477,6 +1477,12 @@ def any(seq, pred=bool): # pylint: disable-msg=W0622
return False
def partition(seq, pred=bool): # # pylint: disable-msg=W0622
"Partition a list in two, based on the given predicate"
return (list(itertools.ifilter(pred, seq)),
list(itertools.ifilterfalse(pred, seq)))
def UniqueSequence(seq):
"""Returns a list with unique elements.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment