CS2333/Homework/util.py

24 lines
621 B
Python
Raw Normal View History

2024-01-15 18:39:16 -04:00
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
2024-01-18 17:25:55 -04:00
def replace_empty_string_with_symbol(strings):
symbol = 'ε'
for i in range(len(strings)):
if strings[i] == '':
strings[i] = symbol
return strings
2024-01-15 18:39:16 -04:00
def print_strings(strings):
2024-01-18 17:25:55 -04:00
strings = replace_empty_string_with_symbol(strings)
# print(len(strings))
print(strings)