Coverage for src/pytest_samples/tools/_iterabletools.py: 100%
9 statements
« prev ^ index » next coverage.py v7.4.2, created at 2024-02-20 19:47 +0000
« prev ^ index » next coverage.py v7.4.2, created at 2024-02-20 19:47 +0000
1"""This module contains useful functions for iterables."""
3from typing import Iterable as _Iterable, Tuple as _Tuple
6def count_truefalse(it: _Iterable[bool]) -> _Tuple[int, int]:
7 """Separately count the occurences of `True` and `False` in
8 and iterable of `bool`s.
10 Args:
11 it (Iterable[bool]): The iterable to process.
13 Returns:
14 Tuple[int, int]: The amount of `True` occurrences,
15 followed by the amount of `False` occurrences.
16 """
17 true = 0
18 false = 0
19 for b in it:
20 if b:
21 true += 1
22 else:
23 false += 1
24 return true, false