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)
| 442 | |
| 443 | |
| 444 | def 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 |
no test coverage detected