Accessing safely and deleting
Alphabet Inc. was formed in 2015 as part of a corporate restructuring of Google. Analyzing the change in stock prices over time is a common task in the world of finance. One way to store stock data is to use the dates as keys and the prices as values in a dictionary.
In this exercise, you access stock closing price data for the company Alphabet for various dates without knowing beforehand if each date has data available. The supplied dictionary alphabet_hist
has datetime
s as keys and stock closing prices as values. A datetime
object named closing_price_date
is supplied.
This exercise is part of the course
Intermediate Python for Finance
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Closing price for day before
day_before_closing_price_date = closing_price_date - timedelta(days=1)
# Safely print closing price day before or None if it's missing
print(alphabet_hist.____(____))