Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
All maps reduce solution in Clear category for Surjection Strings by martin_b
# reduce the two strings to dictionary of sets
# characters from the first string are keys, character from the second string are added to the sets
# check that size of the sets in the dict are not greater than one
# i.e there is only one mapping of the characters from the first string to the second
from collections import defaultdict
from functools import reduce
isometric_strings = lambda s1,s2: all(map(lambda v: len(v)==1,reduce(lambda d,c : d[c[0]].add(c[1]) or d, zip(s1, s2), defaultdict(set)).values()))
Dec. 27, 2020
Comments: