How to generate k+1 length strings from a list of k length strings?

MTD marc.t.davies at gmail.com
Thu Jun 8 06:43:16 EDT 2006


So yeah, just to put it all together, try this. From your two Ks, it
either returns K+1 if it can or an empty string.

def k2k1(string1, string2):
    for c in string1:
        string2 = string2.replace(c,"",1)

    if len(string2) == 1:
        string1 += string2
    else:
        string1 = ""

    return string1


Testing:

print k2k1("abcdadd", "abceadd")

gives:
abcdadde




More information about the Python-list mailing list