1 2 3 4 5 6 7 8 9 10 | s=input("Enter the String->") subs=[] for i in range(1,len(s)+1): for k in range(1,i+1): j=0 while (j+k)<=len(s): if s[j:k+j] not in subs: subs.append(s[j:k+j]) j+=1 print(subs) |
Input: vastgk
Output: ['v', 'a', 's', 't', 'g', 'k', 'va', 'as', 'st', 'tg', 'gk', 'vas', 'ast', 'stg', 'tgk', 'vast', 'astg', 'stgk', 'vastg', 'astgk', 'vastgk']
Comments
Post a Comment
share your thoughts ....