MCPcopy
hub / github.com/django/django / partition

Function partition

django/utils/functional.py:444–455  ·  view source on GitHub ↗

Split the values into two sets, based on the return value of the function (True/False). e.g.: >>> partition(lambda x: x > 3, range(5)) [0, 1, 2, 3], [4]

(predicate, values)

Source from the content-addressed store, hash-verified

442
443
444def partition(predicate, values):
445 """
446 Split the values into two sets, based on the return value of the function
447 (True/False). e.g.:
448
449 >>> partition(lambda x: x > 3, range(5))
450 [0, 1, 2, 3], [4]
451 """
452 results = ([], [])
453 for item in values:
454 results[predicate(item)].append(item)
455 return results

Callers 1

resolve_expressionMethod · 0.90

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected