Wheel of Fortune is a television game show created by Merv Griffin. The show features a competition in which three contestants solve word puzzles — similar to hangman — to win cash and prizes determined by spinning a giant carnival wheel. Each round has a category and a blank word puzzle, with each blank representing a letter in a hidden sentence. The contestants spin the wheel in turn to determine a dollar value and guess a consonant. Calling a correct letter earns the value before the corresponding flipper, multiplied by the number of times the letter appears in the puzzle. Based on the given category and the letters that appear on the puzzle board, the contestant taking turn may then attempt to guess the hidden sentence.
Wheel of Fortune ranks as the longest-running syndicated game show in the United States, with over 6000 episodes aired. TV Guide named it the top-rated syndicated series in a 2008 article, and in 2013 the magazine ranked it at No. 2 in its list of the 60 greatest game shows ever. The program has also come to gain a worldwide following with sixty international adaptations.
The game has been made legendary by the stupidity of some of its candidates. Some blunders forever sit in our collective memory. Did you know the Italian football team AC Melon, president Jill Clinton, the character Wander Women, the style of humor called slipstack, or the characters Batmen and Reban?
For every miraculous New Baby Buggy1 guess on the show, there are dozens more Mythological Hero Achilles2 incidents. Many of these bloopers3 have started to live their own life, which sometimes makes it hard to figure out which ones have really occurred in Wheel of Fortune, and which ones are urban legends that have been fabricates by some funny guys.
Write a function pattern that takes a string as its argument. The function must return the string that is obtained by replacing all vowels (a, e, i, o and u and their upper case versions) in the given string by an underscore (_). This result is called the pattern of the given string.
Write a function bloopers that takes the location of a text file. This text file must contains a sequence of sentences, each on a separate line. The function must return a dictionary whose keys are the patterns of all sentences that occur in the given text file. Each key must be mapped onto the set of sentences from the text file that have this key as their pattern. The function also has two optional parameters length and occurrences, that both have 1 as their default value. The dictionary returned by the function may only contain key/value pairs whose key contains at least length characters and whose value set contains at least occurrences elements.
The following interactive session assumes that the text file wheeloffortune.txt4 is located in the current directory.
>>> pattern('AC Melon')
'_C M_l_n'
>>> pattern('slipstack')
'sl_pst_ck'
>>> pattern('Wander Women')
'W_nd_r W_m_n'
>>> candidates = bloopers('wheeloffortune.txt')
>>> candidates['_C M_l_n']
{'AC Melon', 'AC Milan'}
>>> candidates['sl_pst_ck']
{'slapstick', 'slipstack'}
>>> candidates['W_nd_r W_m_n']
{'Winder Woman', 'Wander Women', 'Wonder Woman'}
>>> bloopers('wheeloffortune.txt', length=13)
{'B_tm_n _nd R_b_n': {'Batman and Robin', 'Batmen and Reban'}}
>>> bloopers('wheeloffortune.txt', occurrences=3)
{'W_nd_r W_m_n': {'Wander Women', 'Winder Woman', 'Wonder Woman'}}
>>> bloopers('wheeloffortune.txt', occurrences=2, length=12)
{'W_nd_r W_m_n': {'Wander Women', 'Winder Woman', 'Wonder Woman'}, 'B_tm_n _nd R_b_n': {'Batman and Robin', 'Batmen and Reban'}}