Dead Poets Society1 is a 1989 American drama film directed by Peter Weir2, written by Tom Schulman3, and starring Robin Williams4. Set in 1959 at the fictional elite conservative boarding school Welton Academy, it tells the story of an English teacher who inspires his students through his teaching of poetry.
The film was a commercial success and received numerous accolades, including Academy Award5 nominations for Best Director, Best Picture, and Best Actor for Robin Williams. The film won the BAFTA Award for Best Film6, the César Award for Best Foreign Film7 and the David di Donatello Award for Best Foreign Film8. Schulman received an Academy Award for Best Original Screenplay9 for his work.
A registry is a text file in which each line describes a person using a fixed number of information fields. Fields are numbered from left to right starting at zero, separated by commas (,) and do not contain commas themselves. The first field always contains the name of the persons, with all persons in the file having unique names. As an example, these are some lines from a registry with information about poets (poets.txt10): their name (field 0), date of birth (field 1) and date of death (field 2).
Thomas Chatterton,1752-11-20,1770-08-24 Phillis Wheatley,,1784-12-05 Percy Bysshe Shelley,1792-08-04,1822-07-08 John Keats,1795-10-31,1821-02-23 Emily Brontë,1818-07-30,1848-12-19 Walt Whitman,1819-05-31, Rupert Brooke,1887-08-03,1915-04-23 Guillaume Apollinaire,1880-08-26,1918-11-09 Wilfred Owen,1893-03-18,1918-11-04 Keith Douglas,1920-01-24,1944-06-09 Sylvia Plath,1932-10-27,1963-02-11
A date field in a registry contains a date in the format YYYY-MM-DD. The corresponding date field remains empty if no date is known for a specific person.
A registry uses the UTF-811 character encoding. When processing such text files, it is recommended to explicitly specify the encoding: encoding='utf-8'.
Your task:
Write a function read_dates that takes the location (str) of a registry and the number $$n \in \mathbb{N}_0$$ (int) of a date field in the registry. The function must return a dictionary (dict) that maps the name (str) of each person in the registry whose date field $$n$$ is not empty onto the corresponding date (datetime.date) in $$n$$-th field of that person.
Write a function lifespan that takes three arguments: i) the name (str) of a person, ii) a dictionary (dict) that maps names (str) of persons onto their date of birth (datetime.date) and iii) a dictionary (dict) that maps names (str) of persons onto their date of death (datetime.date). If both the date of birth and the date of death of the person can be retrieved from the given dictionaries, the function must return a list (list) with a sequence of consecutive years starting with the year of birth and ending with the year of death of the person. Otherwise, an AssertionError must be raised with the message missing information.
Write a function alive that takes two arguments: i) a dictionary (dict) that maps names (str) of persons onto their date of birth (datetime.date) and ii) a dictionary (dict) that maps names (str) of persons onto their date of death (datetime.date). The function must return a dictionary (dict) that maps each year (int) in which at least one person was alive, onto a set (set) containing the names (str) of all persons that were alive during that year (including persons who were born and/or died during that year). The dictionary must only include persons whose year of birth and year of death are known from the given dictionaries.
Write a function wonder_years that takes a dictionary (dict) that maps years (int) onto a set (set) of names (str) of all persons who were alive during that year. The function must return a set (set) containing all the years (int) in which most persons were alive during the same year according to the given dictionary.
Write a function summarized that takes a collection (list, tuple or set) of years (int). The function must return a shorthand notation (str) of the years, where all sequences of two or more consecutive years are abbreviated as the first and the last year in the sequence, separated from each other using a dash (-). Individual years and sequences of consecutive years are listed in chronological order, and separated from each other using a comma (,) and a space. As such, this collection of years
2001, 2002, 2003, 2004, 2012, 2015, 2018, 2019, 2020, 2022
for example has the following shorthand notation
2001-2004, 2012, 2015, 2018-2020, 2022
In the following interactive session we assume the text file poets.txt12 is located in the current directory.
>>> born = read_dates('poets.txt13', 1)
>>> born['Emily Brontë']
datetime.date(1818, 7, 30)
>>> born['Walt Whitman']
datetime.date(1819, 5, 31)
>>> born['Phillis Wheatley']
Traceback (most recent call last):
KeyError: 'Phillis Wheatley'
>>> died = read_dates('poets.txt14', 2)
>>> died['Emily Brontë']
datetime.date(1848, 12, 19)
>>> died['Walt Whitman']
Traceback (most recent call last):
KeyError: 'Walt Whitman'
>>> died['Phillis Wheatley']
datetime.date(1784, 12, 5)
>>> lifespan('Emily Brontë', born, died)
[1818, 1819, 1820, 1821, 1822, 1823, 1824, 1825, 1826, 1827, 1828, 1829, 1830, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841, 1842, 1843, 1844, 1845, 1846, 1847, 1848]
>>> lifespan('Walt Whitman', born, died)
Traceback (most recent call last):
AssertionError: missing information
>>> lifespan('Phillis Wheatley', born, died)
Traceback (most recent call last):
AssertionError: missing information
>>> poets = alive(born, died)
>>> poets[1798]
{'John Keats', 'Percy Bysshe Shelley'}
>>> poets[1895]
{'Guillaume Apollinaire', 'Rupert Brooke', 'Wilfred Owen'}
>>> poets[1952]
{'Sylvia Plath'}
>>> wonder_years(poets)
{1818, 1819, 1820, 1821, 1893, 1894, 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1911, 1912, 1913, 1914, 1915}
>>> summarized({2001, 2002, 2003, 2004, 2012, 2015, 2018, 2019, 2020, 2022})
'2001-2004, 2012, 2015, 2018-2020, 2022'
>>> summarized(lifespan('Emily Brontë', born, died))
'1818-1848'
>>> summarized(wonder_years(poets))
'1818-1821, 1893-1915'
One of the functions in this assignment is a reference to The Wonder Years15, a coming-of-age television series that ran on the American broadcast network ABC16 from January 31, 1988, until May 12, 1993.
The series depicts the social and historical events of the late 1960s and early 1970s as seen through the eyes of 12-year-old Kevin Arnold. In addition to the usual pubertal ailments, he took care of all kinds of teenage social matters. His best friend Paul and the girl next door, Winnie Cooper, were his steady companions. Each episode is narrated by a now grown-up Kevin Arnold who looks back on his childhood years and shares his deepest soul stirrings of his "wonder years" with the viewer. The theme song was Joe Cocker17s' cover of The Beatles18' With a Little Help from My Friends19.