﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28961	Convert result of predicate in the function django.utils.functional.partition to bool	Vitaliy Yelnik	nobody	"
{{{#!python
def partition(predicate, values):
    results = ([], [])
    for item in values:
        results[bool(predicate(item))].append(item)
    return results
}}}

This will make the `partition` function more convenient
{{{#!python
>>> def idf(x): return x
>>> partition(idf, [True, False, '', 1, 2])
([False, ''], [True, 1, 2])
}}}

or make the behaviour of the function more similar to [https://hackage.haskell.org/package/base-4.10.1.0/docs/Data-List.html#v:partition `Haskell partition`]

    The partition function takes a predicate a list and returns the pair of lists of elements which do and do not satisfy the predicate, respectively

{{{#!python
def partition(predicate, values):
    results = ([], [])
    for item in values:
        results[not predicate(item)].append(item)
    return results

>>> def idf(x): return x
>>> partition(idf, [True, False, '', 1, 2])
([True, 1, 2], [False, ''])
}}}"	Cleanup/optimization	closed	Utilities	1.11	Normal	wontfix	functional partition		Unreviewed	0	0	0	0	0	0
