Let's say 's' is a user input string and 'n' is a user input number which is less than the length of the string. Define a function strsplit(s,n) (which will accept both the user input as arguments) and split the input string in to multiple substrings each of n length seperated by a space character.
example:
lets say s="abcdefghij"
and n=3
then functions strsplit(s,n) should print
abc def ghi j
Optimized solution with minimum iterations which I can find is as below
def strsplit(s,n):
ln=len(s)
for i in range(0,ln,n):
print(s[i:i+n],end=" ")
Can be there an improved and optimized solution that the above one?