I am working on a quick and effective way to solve the next problem, but so far I have been able to solve it using a rather slow solution to solve the socket problem. Anyway, here is the description:
So, I have a string of length L, say 'BBBX'. I want to find all possible lines of length L, starting with 'BBBX', that differ by no more than 2 positions and at least 0 positions. In addition, when creating new lines, new characters must be selected from a specific alphabet.
I assume that the size of the alphabet does not matter, so let's say the alphabet in this case ['B', 'G', 'C', 'X'].
So, some rough conclusion would be, 'BGBG', 'BGBC', 'BBGX', etc. For this example, with a line length of 4 s to two permutations, my algorithm will find 67 possible new lines.
I am trying to use itertoolsto solve this problem, but it is difficult for me to find a solution. I try to use itertools.combinations(range(4), 2)to find all possible positions. Then I think about using product()out itertoolsto build all the features, but I'm not sure if there is a way to relate it somehow to the indices from the output combinations().
source
share