Write a program to extract string of N size and having K distict characters


Topic: Write a program to extract string of N size and having K distict characters

Solution

str1 = 'GoodisalwaysGoood'
  
N = 3
  
K = 2
  
res = [] 
for idx in range(0, len(str1) - N + 1): 
    if (len(set(str1[idx: idx + N])) == K): 
        res.append(str1[idx: idx + N]) 
  
print("Extracted Strings : " + str(res)) 



List all Python Programs