如何在字典理解期间从字典中获取值作为整数

How to get the value from a dictionary as an integer during dictionary comprehension

所以这是我目前正在获取 api 信息并将其输入请求模块以使其在控制台中可读的摘要:

response = requests.get(STOCK_ENDPOINT, params=stock_params)
response.raise_for_status()
stock_info = response.json()
yesterday = stock_info["Time Series (Daily)"][f"{YESTERDAY}"]

昨天打印时returns:

{'1. open': '671.64', '2. high': '694.6999', '3. low': '670.32', '4. close': '688.72', '5. adjusted close': '688.72', '6. volume': '21516348', '7. dividend amount': '0.0000', '8. split coefficient': '1.0'}

从这里开始,我现在使用字典理解来获取昨天的收盘价:

y_close = {k:v for (k,v) in yesterday.items() if k == "4. close"}
print(y_close)

哪个returns:

{'4. close': '688.72'}

从这里开始,我对如何从字典中获取数字本身以供以后在数学中使用有点困惑。谁能帮帮我?

已尝试使用 y_close.values() 但 returns

dict_values(['688.72'])

老实说,我对如何进行感到困惑。尝试过使用 for 循环和函数之类的东西,但似乎无法获得原始数字。

a = {'4. close': '688.72'}

float(list(a.values())[0])

float(a['4. close'])

float([v for k,v in a.items()][0])

[float(v) if "close" in k else 0 for k,v in a.items()]