Esophagographers are members of the medical staff who carry out esophagography, defined in Stedman's Medical Dictionary (6th edition, 2008) as radiography of the esophagus using swallowed or injected radiopaque contrast media. The esophagus — commonly known as the foodpipe or gullet — is an organ in vertebrates which consists of a fibromuscular tube through which food passes, aided by peristaltic contractions from the pharynx to the stomach.

esophagus
Scheme of the human digestive tract, with the esophagus marked in red.

In this exercise, however, we are interested in the word esophagographers for a non-medical reason. Esophagographers, sixteen letters long, is the longest English word in which each letter occurs exactly twice. A fourteen-letter word with this property is scintillescent. Twelve-letter words with this property include happenchance and shanghaiings. Ten-letter words with this property include arraigning, concisions, intestines, and horseshoer.

Assignment

Words in which each letter has the same occurrence are called repetition words. You are asked to:

Example

In the following interactive session, we assume that the text file words.txt1 is located in the current directory.

>>> occurrences('CHACHACHA')
{'a': 3, 'h': 3, 'c': 3}
>>> occurrences('Esophagographers')
{'a': 2, 'e': 2, 'g': 2, 'h': 2, 'o': 2, 'p': 2, 's': 2, 'r': 2}
>>> occurrences('happenchance')
{'a': 2, 'c': 2, 'e': 2, 'h': 2, 'n': 2, 'p': 2}

>>> isRepetitionWord('CHACHACHA')
True
>>> isRepetitionWord('Esophagographers')
True
>>> isRepetitionWord('happenchance', minimal_repetition=3)
False

>>> repetitionWords('words.txt', minimal_repetition=2, minimal_length=10)
{'horseshoer', 'intestines'}