From fa64a308c1824e61184df9c928a3667ee81fc415 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 9 Jun 2009 03:22:34 -0400 Subject: [PATCH] Add partition2. --- pytools/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pytools/__init__.py b/pytools/__init__.py index b372dd2..670b07b 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -616,6 +616,19 @@ def partition(criterion, list): +def partition2(iterable): + part_true = [] + part_false = [] + for pred, i in iterable: + if pred: + part_true.append(i) + else: + part_false.append(i) + return part_true, part_false + + + + def product(iterable): from operator import mul return reduce(mul, iterable, 1) -- GitLab