Write a program to split a string by custom length and print it


Topic: Write a program to split a string by custom length and print it

Solution

test_str = 'geeksforgeeks'
  
print("The original string is : " + str(test_str)) 
  
cus_lens = [5, 3, 2, 3] 
res = [] 
strt = 0
for size in cus_lens: 
      
    # slicing for particular length 
    res.append(test_str[strt : strt + size]) 
    strt += size 
      
print("Strings after splitting : " + str(res)) 



List all Python Programs