summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/functional.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py
index c8f8ee33c7..1345d3b005 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -275,4 +275,17 @@ class lazy_property(property):
@wraps(fdel)
def fdel(instance, name=fdel.__name__):
return getattr(instance, name)()
- return property(fget, fset, fdel, doc) \ No newline at end of file
+ return property(fget, fset, fdel, doc)
+
+def partition(predicate, values):
+ """
+ Splits the values into two sets, based on the return value of the function
+ (True/False). e.g.:
+
+ >>> partition(lambda: x > 3, range(5))
+ [1, 2, 3], [4]
+ """
+ results = ([], [])
+ for item in values:
+ results[predicate(item)].append(item)
+ return results \ No newline at end of file