Given a dictionary of animals names as keys and values as years they lived (born-year, death-year), find the names of animals who lived for the given year.
input:
{
"A" : [2004, 2007],
"B" : [1998, 2019],
...
}Output:
for 2006 -> ["A", "B"]My Solution: Iterate through each animal and build a new dictionary as
{
1998 : ["B"],
...
2006: ["A", "B"]
}Can this be optimized and how?