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, ''])
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28961>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
Ticket URL: <https://code.djangoproject.com/ticket/28961#comment:1>
* status: new => closed
* resolution: => wontfix
Comment:
`partition()` isn't a documented function and I don't see a strong reason
to add logic to it that Django's usage doesn't require.
--
Ticket URL: <https://code.djangoproject.com/ticket/28961#comment:2>