Sliding String Windows
When you need to analyze a string piece by piece, it is useful to take consecutive windows of the same length. The function slices receives a digit string series and returns all substrings of length length, moving from left to right one character at a time. If the parameters are invalid, raise ValueError.
Примеры
Ввод
("01234", 1)Вывод
["0", "1", "2", "3", "4"]Ввод
("97867564", 2)Вывод
["97", "78", "86", "67", "75", "56", "64"]Ввод
("12345", 5)Вывод
["12345"]Нужно реализовать
def slices(series: str, length: int) -> list[str]:
Теги
stringssliding-windowlists
Entre para ver seu histórico de envios
EntrarEntre para usar o AI Mentor
EntrarVisible tests
1
Input
"01234", 1Expected
["0","1","2","3","4"]2
Input
"97867564", 2Expected
["97","78","86","67","75","56","64"]3
Input
"12345", 5Expected
["12345"]4
Input
"918493904243", 5Expected
["91849","18493","84939","49390","93904","39042","90424","04243"]5
Input
"918493904243", 1Expected
["9","1","8","4","9","3","9","0","4","2","4","3"]6
Input
"01234!", 1Expected
["0","1","2","3","4","!"]Focus radio
Paused · SomaFM · Fluid