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

Commit 25d803f

Browse files
committed
Update docstrings in "sequence.func"
1 parent 60472d3 commit 25d803f

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

src/sequences/func.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ def is_palindrome(origin: Union[str, int], /) -> bool:
1414
"""
1515
Return a palindrome check result
1616
17-
:param origin: value to test
18-
:type origin: str | int
19-
20-
:return: return a palindrome check result
21-
:rtype: bool
22-
2317
This function implements two pointers method. The left pointer is
2418
initialized at the beginning of an origin string, and the right one -
2519
at the end. The check cycle compares characters at left and right
@@ -28,6 +22,12 @@ def is_palindrome(origin: Union[str, int], /) -> bool:
2822
returns True. Punctuation, word boundaries and capitalization are
2923
ignored.
3024
25+
:param origin: value to test
26+
:type origin: str | int
27+
28+
:return: return a palindrome check result
29+
:rtype: bool
30+
3131
Usage:
3232
3333
>>> assert is_palindrome("aba") is True
@@ -64,7 +64,7 @@ def get_longest_palindrome(origin: str, /) -> str:
6464
"""
6565
Return the longest palindrome substring from the given input
6666
67-
:param origin:
67+
:param origin: an origin string to find palindromes in
6868
:type origin: str
6969
7070
:return: the longest palindrome
@@ -79,8 +79,21 @@ def get_longest_palindrome(origin: str, /) -> str:
7979

8080
size: int = len(origin)
8181

82-
# noinspection PyMissingOrEmptyDocstring
8382
def expand(left: int, right: int) -> int:
83+
"""
84+
85+
This inner function uses closure to "size" and "origin" objects
86+
from outer score, and tries to expand to left and right from
87+
the specified index of the origin string, until palindrome and
88+
expansion checks are pass.
89+
90+
:param left: left starting expansion index
91+
:type left: int
92+
:param right: right starting expansion index
93+
:type right: int
94+
95+
"""
96+
8497
while left >= 0 and right < size and origin[left] == origin[right]:
8598
left -= 1
8699
right += 1
@@ -124,10 +137,10 @@ def get_palindrome_squares(limit: int, /) -> List[int]:
124137
125138
Range begins with 0.
126139
127-
:param limit:
140+
:param limit: the range limitation value
128141
:type limit: int
129142
130-
:return:
143+
:return: a list of palindrome squares within a range
131144
:rtype: list
132145
133146
"""
@@ -139,18 +152,18 @@ def are_parentheses_balanced(origin: str, /) -> bool:
139152
"""
140153
Return a validation result for a given parentheses sequence
141154
142-
:param origin: a parentheses sequence to validate
143-
:type origin: str
144-
145-
:return: a validation result
146-
:rtype: bool
147-
148155
Validation rules:
149156
150157
- each opening parentheses must be closed by the same type parentheses
151158
- open parentheses must be closed in the correct order
152159
- any non-parentheses characters are to be ignored
153160
161+
:param origin: a parentheses sequence to validate
162+
:type origin: str
163+
164+
:return: a validation result
165+
:rtype: bool
166+
154167
Usage:
155168
156169
>>> assert are_parentheses_balanced("({[]})") is True
@@ -240,6 +253,9 @@ def get_consecutive_slices(origin: str, n: int) -> List[List[int]]:
240253
"""
241254
Return possible slices of string as a collection of lists of digits
242255
256+
Given a string of digits and an integer `n`, this function returns all
257+
consecutive slices of length `n` from the string.
258+
243259
:param origin: the input string of digits
244260
:type origin: str
245261
:param n: the length of slices to be extracted
@@ -250,9 +266,6 @@ def get_consecutive_slices(origin: str, n: int) -> List[List[int]]:
250266
251267
:raise: ValueError
252268
253-
Given a string of digits and an integer `n`, this function returns all
254-
consecutive slices of length `n` from the string.
255-
256269
Usage:
257270
258271
>>> assert get_consecutive_slices("0123", 1) == [[0], [1], [2], [3]]

0 commit comments

Comments
 (0)