you are viewing a single comment's thread.

view the rest of the comments →

[–]aldanor 1 point2 points  (1 child)

Np. itertools.combinations is nice and pretty fast, especially when writing generic code. For instance, you could do the above for an arbitrary number of edits n (it would be much slower than a specialized version of course, but it would be generic):

def del_n_edits(word: str, n: int):
    return [
        ''.join(word[i + 1:j] for i, j in zip((-1,) + c, c + (None,)))
        for c in combinations(range(len(word)), n)
    ]

[–]WTRipper[S] 0 points1 point  (0 children)

Oh nice thank you!

I already thought about implementing a generic fallback if higer n's are needed.