find all substrings of length k python code example
Example: python get all substrings of length k
string = input()
k = int(input())
answers = []
for start in range(len(string)):
temp = string[start: start + k]
if len(temp) == k:
answers.append(temp)
print(answers)
answers = [string[start: start + k] for start in range(len(string))
if len(string[start: start + k]) == k]
# in single line but less efficient
print(answers)