partition

sknano.core.partition(pred, iterable)[source] [edit on github][source]

Use a predicate to partition entries into false entries and true entries.

Parameters:
  • pred (callable) – callable function taking one argument and returning True or False.
  • iterable (Iterable) –
Returns:

Return type:

tuple of Iterables

Examples

>>> from sknano.core import partition
>>> is_odd = lambda x: x % 2 != 0
>>> p = partition(is_odd, range(10))
>>> [print(i) for i in p]
[[0, 2, 4, 6, 8], [1, 3, 5, 7, 9]]