Loading...
Loading...
Two words are a one-to-one match when each letter of the first word is always replaced by the same letter of the second word, and no two different letters of the first word map to the same letter. A letter may map to itself.
Print True if the two words match in this way, otherwise False. Words of different length never match.
True or False.Example 1
Input
egg add
Output
True
e maps to a and g maps to d, always the same way.
Example 2
Input
foo bar
Output
False
The letter o would need to map to both a and r.
Try the problem first. Open one hint at a time.
Keep one dictionary for first-to-second letters and one for second-to-first letters.
On every position, the stored partner must be the same letter you see now, in both dictionaries. Stop at the first mismatch.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor