Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Short solution - using dictionary and comparing strings solution in Clear category for Surjection Strings by Pelmen323
def isometric_strings(a, b):
d = dict(zip(tuple(a), tuple(b)))
l = list(a)
return True if ''.join([d.get(l[i]) for i in range(len(l))]) == b else False
# a - 'foo', b - 'bar'
# Dictionary is created - since the keys should be unique, non-unique keys will be overriden:
# {'f': 'b', 'o': 'r'}
# The string 'a' is converted to the list ['f', 'o', 'o'], all its letters are replaced using newly created dictionary (['b', 'r', 'r']) and then it is converted back to string:
# Isometric string will survive that operation (it will become equal to string 'b' - egg -- egg), while non-isometric - not (brr -- bar)
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
assert isometric_strings("gogopy", "doodle") == False
print("Coding complete? Click 'Check' to earn cool rewards!")
Aug. 31, 2021
Comments: