I have created a script that uses the following code to iterate over all combinations of characters in the sCharacters string:
sCharacters = "abcdefghijklmnopqrstuvwxyz0123456789" iKeyLength = len(sCharacters) for sCharacterCombination in itertools.product(sCharacters, repeat=iKeyLength): # Do Stuff Here
However I am only interested in combinations where no single character is represented more than n number of times in the sCharacterCombination.
Eg; I want to filter out strings like
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab and only get ones like
I tried just checking each
sCharacterCombination, but this is no good as I still have to iterate over a mountain of items I will never use.
How can I get the iterator to create the list based on each item having no single character represented more than
n number of times in the first place, so I don't have to iterate over items I will not use?
It would be awesome if I could say:
- Max number of times a single character could be represented in the sCharacterCombination.
- Max times a single character could be represented in a row.
That would allow me to say a single character could appear in the sCharacterCombination a max of four times, but it could not be in a row more than twice. E.g. This is ok
1121... but this is not
Thank you for your time.