Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Surjection Strings by sawako.oono
import itertools
import string
import re
def isometric_strings(str1: str, str2: str) -> bool:
alpha = [ch for ch in string.ascii_lowercase]
chset = list(set(list(str2)))
setofx = itertools.combinations(alpha,len(chset))
perm = []
for i in setofx:
for j in itertools.permutations(i):
perm.append(j)
for comb in perm:
test = str2
transTable = test.maketrans("".join(chset),"".join(comb),)
test = test.translate(transTable)
if test == str1:
return True
else:
continue
return False
if __name__ == '__main__':
print("Example:")
print(isometric_strings('add', 'egg'))
# These "asserts" are used for self-checking and not for an auto-testing
#assert isometric_strings('add', 'egg') == True
assert isometric_strings('foo', 'bar') == False
assert isometric_strings('', '') == True
assert isometric_strings('all', 'all') == True
print("Coding complete? Click 'Check' to earn cool rewards!")
May 26, 2021
Comments: