An isogram is a word in which no letter is repeated. Examples of isograms are uncopyrightable and ambidextrously. Conveniently, the word itself is an isogram.
Theoretically the limit is 26 letters, but that's an Everest that no one has scaled. In his book Language on Vacation: An Olio of Orthographical Oddities1, Dmitri Borgmann has conquered some lesser peaks trying to find the longest isogrammic word. The longest one he found was dermatoglyphics at 15 letters. He coins several longer hypothetical words, such as thumbscrew-japingly (18 letters, defined as "as if mocking a thumbscrew") and — with the uttermost limit in the way of verbal creativeness — pubvexingfjord-schmaltzy (23 letters, defined as "as if in the manner of the extreme sentimentalism generated in some individuals by the sight of a majestic fjord, which sentimentalism is annoying to the clientele of an English inn"). Maybe what we lack is imagination.
An anagram is a type of word
play, the result of rearranging the letters of a word or phrase to produce
a new word or phrase, using all original letters exactly once. For
example, the word Torchwood can be rearranged into Doctor Who.
Any word or phrase that exactly reproduces the letters in another order is
an anagram. However, the goal of serious or skilled anagrammatists is to
produce anagrams that in some way reflect or comment on the subject. Such
an anagram may be a synonym or antonym of its subject, a parody, a
criticism, or praise. For example, William Shakespeare is an
anagram of I am a weakish speller.
In this exercise, words are represented as strings that only contain letters. Your task is to implement the following three functions, that each take one or two words. All functions must treat the given words in a case insensitive way.
Write a function occurrences that takes a single word. The function must return a list of 26 integers, each indicating the number of occurrences in the given word of the letter at the corresponding position in the alphabet.
Use the function occurrences to write a function isogram that takes a single word. The function must return a Boolean value that indicates whether or not the given word is an isogram.
Use the function occurrences to write a function anagram that takes two words. The function must return a Boolean value that indicates whether or not the given words are anagrams of each other.
>>> occurrences('ambidextrously')
[1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0]
>>> occurrences('DOCTORWHO')
[0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0]
>>> occurrences('uncopyrightable')
[1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0]
>>> isogram('ambidextrously')
True
>>> isogram('DOCTORWHO')
False
>>> isogram('uncopyrightable')
True
>>> anagram('DOCTORWHO', 'Torchwood')
True
>>> anagram('isogram', 'anagram')
False
>>> anagram('Aristotelian', 'retaliations')
True