How to generate all k-1 level substrings of a string?

Girish Sahani girish at cse.iitb.ac.in
Mon Jun 5 21:28:57 EDT 2006


I want to generate all substrings of size k-1 from a string of size k.
e.g 'abcd' should give me ['abc','abd','bcd','acd']
Order of these strings in the list doesnt matter.
Also order doesnt matter inside the string e.g 'abc' or 'bca' or 'bac' is
the same.
I wrote the following code but it doesnt give the full output:

subsetList = []
for element in prunedNew:
    for i in range(0,2):
        subsetList.append(element[i:i+len(element)-1])
        continue
    continue
 return prunedNew


Thanks in Advance,
girish





More information about the Python-list mailing list