MCPcopy Index your code
hub / github.com/idank/explainshell / group_continuous

Function group_continuous

explainshell/util.py:8–26  ·  view source on GitHub ↗

>>> list(group_continuous([1, 2, 4, 5, 7, 8, 10])) [[1, 2], [4, 5], [7, 8], [10]] >>> list(group_continuous(range(5))) [[0, 1, 2, 3, 4]]

(items, key=None)

Source from the content-addressed store, hash-verified

6
7
8def group_continuous(items, key=None):
9 """
10 >>> list(group_continuous([1, 2, 4, 5, 7, 8, 10]))
11 [[1, 2], [4, 5], [7, 8], [10]]
12 >>> list(group_continuous(range(5)))
13 [[0, 1, 2, 3, 4]]
14 """
15 if key is None:
16
17 def identity(value):
18 return value
19
20 key_func = identity
21 else:
22 key_func = key
23 for _, grouped in itertools.groupby(
24 enumerate(items), lambda ix: ix[0] - key_func(ix[1])
25 ):
26 yield list(map(itemgetter(1), grouped))
27
28
29class Peekable:

Callers

nothing calls this directly

Calls 1

mapFunction · 0.85

Tested by

no test coverage detected