Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 30e771e

Browse files
committed
Update "consecutive slices" function
1 parent cae2fd5 commit 30e771e

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/sequences/func.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ def add_spaces(origin: str) -> str:
247247
return "".join(f" {c}" if c.isupper() else c for c in origin).lstrip()
248248

249249

250-
def get_consecutive_slices(origin: str, n: int) -> List[List[int]]:
250+
def get_consecutive_slices(origin: str, n: int) -> List[str]:
251251
"""
252-
Return possible slices of string as a collection of lists of digits
252+
Return possible slices of string as a collection consecutive lists
253253
254254
Given a string of digits and an integer `n`, this function returns all
255255
consecutive slices of length `n` from the string.
@@ -259,7 +259,7 @@ def get_consecutive_slices(origin: str, n: int) -> List[List[int]]:
259259
:param n: the length of slices to be extracted
260260
:type n: int
261261
262-
:return: a list containing sublists of consecutive slices of length "n"
262+
:return: a list containing consecutive slices of length "n"
263263
:rtype: list
264264
265265
:raise: ValueError
@@ -276,7 +276,6 @@ def get_consecutive_slices(origin: str, n: int) -> List[List[int]]:
276276
if size < n:
277277
raise ValueError("slice size is bigger than origin length")
278278

279-
origin = list(map(int, origin))
280279
result = []
281280
idx = 0
282281

tests/sequences/func_test.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,14 @@ def test_add_space():
8282

8383

8484
def test_get_consecutive_slices():
85-
assert sequences.get_consecutive_slices("0123", 1) == [[0], [1], [2], [3]]
85+
assert sequences.get_consecutive_slices("0123", 1) == ["0", "1", "2", "3"]
8686
assert (
87-
sequences.get_consecutive_slices("0123", 2) == [[0, 1], [1, 2], [2, 3]]
87+
sequences.get_consecutive_slices("0123", 2) == ["01", "12", "23"]
8888
)
8989
assert (
90-
sequences.get_consecutive_slices("0123", 3) == [[0, 1, 2], [1, 2, 3]]
90+
sequences.get_consecutive_slices("0123", 3) == ["012", "123"]
9191
)
9292

9393
with pytest.raises(ValueError,
9494
match="slice size is bigger than origin length"):
9595
sequences.get_consecutive_slices("0123", 5)
96-
with pytest.raises(ValueError):
97-
sequences.get_consecutive_slices("abcdefg", 1)

0 commit comments

Comments
 (0)