Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/unblob/iter_utils.py: 46%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import itertools
2from collections.abc import Iterable, Iterator
3from typing import TypeVar
5T = TypeVar("T")
8def pairwise(iterable: Iterable[T]) -> Iterator[tuple[T, T]]:
9 # Copied from Python 3.10
10 # pairwise('ABCDEFG') --> AB BC CD DE EF FG
11 a, b = itertools.tee(iterable)
12 next(b, None)
13 return zip(a, b)
16def get_intervals(values: list[int]) -> list[int]:
17 """Get all the intervals between numbers.
19 It's similar to numpy.diff function.
21 Example:
22 -------
23 >>> get_intervals([1, 4, 5, 6, 10])
24 [3, 1, 1, 4]
26 """
27 all_diffs = []
28 for value, next_value in pairwise(values):
29 all_diffs.append(next_value - value)
30 return all_diffs