Question: Question 4 PROMPT: Create a program that replaces holidays with dates: A.) Create a dictionary of 8 or more holidays for 2018 listing dates as
Question 4 PROMPT:
"Create a program that replaces holidays with dates:
A.)
Create a dictionary of 8 or more holidays for 2018 listing dates as strings of the form '12/31/2018'. If a holiday consists of multiple days (Passover, Ramadan, etc., only include the first date in the dictionary. Only consider holidays that consist of a single word. For our purposes, alternative spellings of a Holiday could be viewed as a different holiday, even though they will have the same date associated with them. Sample one word holidays include: Easter, Chanukah, Christmas, Halloween, Thanksgiving, Kwanzaa, Hanukkah, Passover, Ramadan, Diwali, Chanukkah, Whitsunday, Pentecost, Whit-tuesday, and many others\
Write a function that uses the dictionary to replace holidays in a string with the corresponding dates. The function should work as follows:
It should splits the string into words (split at spaces)
It should check if each word is in the dictionary and replace it in the list with its value, e.g., the list ['I','wish','you','a','merry','Christmas'] should become: ['I','wish','you','a','merry', '12/25/2018']
It should convert this list into a string using a for loop. Start with the empty string and add the items in the list, separated by spaces. Return the resulting string.
Your function should deal with punctuation and capitalization in some way. For capitalization, you could simply convert to lower case and only store lowercase items in your dictionary. For punctuation, you could strip off characters that are periods or commas. Smoother ways of handling these issues are worth more points.
B.) Alter this program to handle holidays that consist of multiple words. I would suggest doing the following (but other methods are possible):
Make a dictionary keyed by the first word in the holiday.
The value for each entry should be a list beginning with the date and followed by the remaining words of the holiday name (in order).
The loop would start recognizing a holiday when the first word was encountered and only finish recognizing the holiday when all words in order were recognized. At that point, the sequence of words would be replaced by the date.
This would need to be modified a little more to handle cases where the same word begins multiple holiday names (e.g., Good Friday and Good Saturday). For example, you could assume all holiday names have at most 2 words and have each possible first word linked to a dictionary of second words plus a date. There are several ways to extend this to holiday names of more than 2 words."
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
