CS2333/util.py
2024-01-15 18:39:16 -04:00

14 lines
402 B
Python

def get_all_strings_with_a_given_alphabet_and_length(alphabet, length):
strings = ['']
for i in range(length):
s = [s + c for s in strings for c in alphabet]
strings += s
# Remove duplicates (set() isn't as nice as it doesn't preserve order, at least for verification purposes)
strings = list(dict.fromkeys(strings))
return strings
def print_strings(strings):
print(strings, len(strings))