I have a list of strings all of length k. For every pair of k length
strings which have k-1 characters in common, i want to generate a k+1
length string(the k-1 common characters + 2 not common characters).
e.g i want to join 'abcd' with bcde' to get 'abcde' but i dont want to
join 'abcd' with 'cdef'
Currently i'm joining every 2 strings, then removing duplicate characters
from every joined string and finally removing all those strings whose
length != k+1.Here's the code i've written:
def withoutDup(string): #check
seen = {}
chars = []
for c in string:
if c not in seen.keys():
chars.append(c)
seen[c] = 1
continue
return ''.join(chars)
def genColocations(prunedK):
prunedNew = prunedNew1 = subsetList = []
for i in range(0,len(prunedK) - 1,1):
for k in range(1,len(prunedK),1):
if i+k <= len(prunedK) -1:
colocn = prunedK[i] + prunedK[i+k]
prunedNew1.append(colocn)
continue
continue
for string in prunedNew1:
stringNew = withoutDup(string)
prunedNew.append(stringNew)
continue
But it is quite bad in the time aspect :(. Please help me out.
Thanks in advance,
girish