From 2de64672faed917bae951888566f479dad6b63ff Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 11 Mar 2010 13:33:29 +0100
Subject: [PATCH] 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: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/utils.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/utils.py b/lib/utils.py
index a6b677c0b..014475524 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -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.
 
-- 
GitLab