I am trying to write a function in Python
def all_strings(alpha,length):
# ...
which takes a given alphabet (alpha
) and a length
and returns all possible combinations of the alphabet restricted by the given length.
For example:
all_strings({0,1}, 3)
should return:
['000', '001', '010', '011', '100', '101', '110', '111']
I tried looping through the set but you cannot iterate through a set in python. I also considered itertools however permutations
and combinations
do not allow repetition of numbers.