mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Add recipe for subslices (GH-31095)
This commit is contained in:
parent
f5ebec4d3e
commit
a77de58108
1 changed files with 6 additions and 0 deletions
|
@ -893,6 +893,12 @@ which incur interpreter overhead.
|
|||
yield from it
|
||||
return true_iterator(), remainder_iterator()
|
||||
|
||||
def subslices(seq):
|
||||
"Return all contiguous non-empty subslices of a sequence"
|
||||
# subslices('ABCD') --> A AB ABC ABCD B BC BCD C CD D
|
||||
slices = starmap(slice, combinations(range(len(seq) + 1), 2))
|
||||
return map(operator.getitem, repeat(seq), slices)
|
||||
|
||||
def powerset(iterable):
|
||||
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
|
||||
s = list(iterable)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue