Write a Python lambda function that extracts the year from a string formatted as ‘DD-MM-YYYY’. The function should accept a string and return an integer.
Example 1:
Input: "01-01-2020"
Output: 2020
Example 2:
Input: "31-12-2023"
Output: 2023
Use Python’s string slicing technique to extract the year from the string.
# Define the lambda function
extract_year = lambda date: int(date[-4:])
# Test the function
print(extract_year("01-01-2020")) # Output: 2020
print(extract_year("31-12-2023")) # Output: 2023
NOTEOwing to browser caching, any code input into the Trinket IDE might carry over across page refreshes or when transitioning between different questions. To commence with a clean slate, either click on the 'Reset Button' found within the IDE's Hamburger icon (☰) menu or resort to using Chrome's Incognito Mode.