Top hottest years ================= Exercise -------- .. interactive_code_block:: :caption: Display a specified amount of the top hottest years hottest_year_count = 10 # Global land and ocean temperature anomalies # SOURCE: https://www.ncei.noaa.gov/access/monitoring/climate-at-a-glance/global/time-series/globe/land_ocean/ann/10/1880-2022 data = { 1880: -0.12, 1881: -0.08, 1882: -0.10, 1883: -0.18, 1884: -0.27, 1885: -0.25, 1886: -0.24, 1887: -0.29, 1888: -0.13, 1889: -0.08, 1890: -0.34, 1891: -0.26, 1892: -0.31, 1893: -0.33, 1894: -0.32, 1895: -0.25, 1896: -0.10, 1897: -0.10, 1898: -0.28, 1899: -0.16, 1900: -0.08, 1901: -0.16, 1902: -0.26, 1903: -0.38, 1904: -0.46, 1905: -0.28, 1906: -0.21, 1907: -0.39, 1908: -0.43, 1909: -0.45, 1910: -0.41, 1911: -0.45, 1912: -0.34, 1913: -0.32, 1914: -0.15, 1915: -0.10, 1916: -0.33, 1917: -0.40, 1918: -0.31, 1919: -0.25, 1920: -0.23, 1921: -0.16, 1922: -0.25, 1923: -0.25, 1924: -0.24, 1925: -0.18, 1926: -0.07, 1927: -0.17, 1928: -0.18, 1929: -0.33, 1930: -0.11, 1931: -0.06, 1932: -0.13, 1933: -0.26, 1934: -0.11, 1935: -0.16, 1936: -0.12, 1937: -0.01, 1938: -0.02, 1939: 0.01, 1940: 0.16, 1941: 0.27, 1942: 0.11, 1943: 0.11, 1944: 0.28, 1945: 0.18, 1946: -0.01, 1947: -0.03, 1948: -0.05, 1949: -0.07, 1950: -0.15, 1951: 0.00, 1952: 0.04, 1953: 0.13, 1954: -0.10, 1955: -0.13, 1956: -0.18, 1957: 0.07, 1958: 0.13, 1959: 0.08, 1960: 0.05, 1961: 0.10, 1962: 0.11, 1963: 0.12, 1964: -0.14, 1965: -0.07, 1966: -0.01, 1967: 0.00, 1968: -0.03, 1969: 0.11, 1970: 0.06, 1971: -0.07, 1972: 0.04, 1973: 0.19, 1974: -0.06, 1975: 0.01, 1976: -0.07, 1977: 0.21, 1978: 0.12, 1979: 0.23, 1980: 0.28, 1981: 0.32, 1982: 0.19, 1983: 0.36, 1984: 0.17, 1985: 0.16, 1986: 0.24, 1987: 0.38, 1988: 0.39, 1989: 0.30, 1990: 0.45, 1991: 0.39, 1992: 0.24, 1993: 0.28, 1994: 0.35, 1995: 0.47, 1996: 0.32, 1997: 0.52, 1998: 0.65, 1999: 0.44, 2000: 0.43, 2001: 0.57, 2002: 0.62, 2003: 0.64, 2004: 0.58, 2005: 0.67, 2006: 0.64, 2007: 0.62, 2008: 0.54, 2009: 0.64, 2010: 0.72, 2011: 0.58, 2012: 0.64, 2013: 0.67, 2014: 0.74, 2015: 0.93, 2016: 0.99, 2017: 0.91, 2018: 0.82, 2019: 0.94, 2020: 0.98, 2021: 0.84 } # Create a list of years sorted by their temperature anomaly # SEE https://docs.python.org/3/library/functions.html#sorted data_sorted = # ... # Create a list of the hottest years (list length = hottest_year_count) hottest_years = # ... # Which year was the earliest hottest year in the list? earliest_hottest_year = # ... # Which year was the latest hottest year in the list? latest_hottest_year = # ... # Within how many years did the hottest years occur? duration = # ... print('\\nThe top {} hottest years have occurred within {} years from {} until {}.'.format(hottest_year_count, duration, earliest_hottest_year, latest_hottest_year)) print('\\nYear | Temp') print('-----+-----') for year, temperature in data.items(): if year in hottest_years: print('{} | {}'.format(year, temperature))